public PIManager() { i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); try { i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); lcd = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); } catch (Exception e) { Console.WriteLine("Lcd device not found."); } Info = new List <string>(); greenPulse = 0; orangePulse = 0; redPulse = 0; grovePi.PinMode(GrovePort.DigitalPin4, PinMode.Output); grovePi.PinMode(GrovePort.DigitalPin3, PinMode.Output); grovePi.PinMode(GrovePort.DigitalPin2, PinMode.Output); }
internal RotaryAngleSensor(GrovePi device, Pin pin) { if (device == null) throw new ArgumentNullException(nameof(device)); device.PinMode(_pin, PinMode.Input); _device = device; _pin = pin; }
internal DHTTemperatureAndHumiditySensor(GrovePi device, Pin pin, DHTModel model) { if (device == null) throw new ArgumentNullException(nameof(device)); _device = device; _pin = pin; _model = model; }
static void Main(string[] args) { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); WriteLine($"Manufacturer: {grovePi.GrovePiInfo.Manufacturer}"); WriteLine($"Board: {grovePi.GrovePiInfo.Board}"); WriteLine($"Firmware version: {grovePi.GrovePiInfo.SoftwareVersion}"); }
internal RealTimeClock(GrovePi device, Pin pin) { if (device == null) { throw new ArgumentNullException(nameof(device)); } _device = device; _pin = pin; }
public static GrovePi GrovePi(byte address) { if (device_ == null) { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, address); GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); } return(device_); }
internal RotaryEncoder(GrovePi device, Pin pin) { if (device == null) { throw new ArgumentNullException(nameof(device)); } _device = device; _pin = pin; }
/// <summary> /// UltrasonicSensor constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public UltrasonicSensor(GrovePi grovePi, GrovePort port) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Grove port {port} not supported.", nameof(port)); } _grovePi = grovePi; _port = port; }
internal ChainableRgbLed(GrovePi device, Pin pin) { if (device == null) { throw new ArgumentNullException(nameof(device)); } _device = device; _pin = pin; }
internal FourDigitDisplay(GrovePi device, Pin pin) { if (device == null) { throw new ArgumentNullException(nameof(device)); } _device = device; _pin = pin; }
internal AccelerometerSensor(GrovePi device, Pin pin) { if (device == null) { throw new ArgumentNullException(nameof(device)); } _device = device; _pin = pin; }
internal AirQualitySensor(GrovePi device, Pin pin) { if (device == null) { throw new ArgumentNullException(nameof(device)); } device.PinMode(_pin, PinMode.Input); _device = device; _pin = pin; }
/// <summary> /// AnalogSensor constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public AnalogSensor(GrovePi grovePi, GrovePort port) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Grove port {port} not supported.", nameof(port)); } _grovePi = grovePi; _port = port; _grovePi.PinMode(_port, PinMode.Input); }
internal TemperatureAndHumiditySensor(GrovePi device, Pin pin, TemperatureAndHumiditySensorModel model) { if (device == null) { throw new ArgumentNullException(nameof(device)); } _device = device; _pin = pin; _model = model; }
/// <summary> /// DigitalInput constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public DigitalInput(GrovePi grovePi, GrovePort port) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException(nameof(port), "Grove port not supported"); } _grovePi = grovePi; Port = port; _grovePi.PinMode(Port, PinMode.Input); }
/// <summary> /// PwmOutput constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public PwmOutput(GrovePi grovePi, GrovePort port) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Grove port {port} not supported.", nameof(port)); } _grovePi = grovePi; _port = port; _grovePi.PinMode(_port, PinMode.Output); Value = 0; }
/// <summary> /// LedBar constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> /// <param name="orientation">Orientation, Green to red is default</param> public LedBar(GrovePi grovePi, GrovePort port, LedBarOrientation orientation) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Grove port {port} not supported.", nameof(port)); } _grovePi = grovePi; _port = port; _orientation = orientation; _grovePi.WriteCommand(GrovePiCommand.LedBarInitialization, port, (byte)_orientation, 0); _level = 0; }
/// <summary> /// Initialize the DHT Sensor class /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> /// <param name="dhtType">The DHT type</param> public DhtSensor(GrovePi grovePi, GrovePort port, DhtType dhtType) { if (!SupportedPorts.Contains(port)) { throw new ArgumentException($"Grove port {port} not supported.", nameof(port)); } _grovePi = grovePi; DhtType = dhtType; _port = port; // Ask for the temperature so we will have one in cache _grovePi.WriteCommand(GrovePiCommand.DhtTemp, _port, (byte)DhtType, 0); }
static void Main(string[] args) { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); UltrasonicSensor sensor = new UltrasonicSensor(grovePi, Iot.Device.GrovePiDevice.Models.GrovePort.DigitalPin7); while (true) { Console.WriteLine(sensor.Value); Thread.Sleep(200); } }
static void Main(string[] args) { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); using GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); Iot.Device.GrovePiDevice.Sensors.LedBar bar = new Iot.Device.GrovePiDevice.Sensors.LedBar(grovePi, GrovePort.DigitalPin7); for (byte i = 1; i <= 10; ++i) { bar.SetOneLed(i, true); Console.WriteLine($"{i}\t{bar.Value}"); Thread.Sleep(1000); } bar.SetAllLeds(0); }
static void Main(string[] args) { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); grovePi.PinMode(GrovePort.DigitalPin5, PinMode.Output); Led led = new Led(grovePi, GrovePort.DigitalPin5); for (int i = 0; i < 25; ++i) { Console.WriteLine($"Blink no {i}"); led.Value = PinValue.High; Thread.Sleep(500); led.Value = PinValue.Low; Thread.Sleep(500); } }
public GrovePiService() { I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); GrovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); // Lights KitchenLight = new Led(GrovePi, GrovePort.DigitalPin2); LivingRoomLight = new Led(GrovePi, GrovePort.DigitalPin3); BathroomLight = new Led(GrovePi, GrovePort.DigitalPin4); // Sensors TempHumid = new DhtSensor(GrovePi, GrovePort.DigitalPin8, DhtType.Dht11); // Display var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E)); var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62)); Display = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice); }
/// <summary> /// Main entry point /// </summary> /// <param name="args">unused</param> public static void Main(string[] args) { Console.WriteLine("Hello GrovePi!"); PinValue relay = PinValue.Low; I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress); _grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings)); Console.WriteLine($"Manufacturer :{_grovePi.GrovePiInfo.Manufacturer}"); Console.WriteLine($"Board: {_grovePi.GrovePiInfo.Board}"); Console.WriteLine($"Firmware version: {_grovePi.GrovePiInfo.SoftwareVersion}"); // Specific example to show how to read directly a pin without a high level class _grovePi.PinMode(GrovePort.AnalogPin0, PinMode.Input); _grovePi.PinMode(GrovePort.DigitalPin2, PinMode.Output); _grovePi.PinMode(GrovePort.DigitalPin3, PinMode.Output); _grovePi.PinMode(GrovePort.DigitalPin4, PinMode.Input); // 2 high level classes UltrasonicSensor ultrasonic = new UltrasonicSensor(_grovePi, GrovePort.DigitalPin6); DhtSensor dhtSensor = new DhtSensor(_grovePi, GrovePort.DigitalPin7, DhtType.Dht11); int poten = 0; while (!Console.KeyAvailable) { Console.Clear(); poten = _grovePi.AnalogRead(GrovePort.AnalogPin0); Console.WriteLine($"Potentiometer: {poten}"); relay = (relay == PinValue.Low) ? PinValue.High : PinValue.Low; _grovePi.DigitalWrite(GrovePort.DigitalPin2, relay); Console.WriteLine($"Relay: {relay}"); _grovePi.AnalogWrite(GrovePort.DigitalPin3, (byte)(poten * 100 / 1023)); Console.WriteLine($"Button: {_grovePi.DigitalRead(GrovePort.DigitalPin4)}"); Console.WriteLine($"Ultrasonic: {ultrasonic}"); dhtSensor.Read(); Console.WriteLine($"{dhtSensor.DhtType}: {dhtSensor}"); Thread.Sleep(2000); } }
/// <summary> /// Grove temperature sensor constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public GroveTemperatureSensor(GrovePi grovePi, GrovePort port) : base(grovePi, port) { }
internal ChainableRgbLed(GrovePi device, Pin pin) { if (device == null) throw new ArgumentNullException(nameof(device)); _device = device; _pin = pin; }
internal RealTimeClock(GrovePi device, Pin pin) { if (device == null) throw new ArgumentNullException(nameof(device)); _device = device; _pin = pin; }
/// <summary> /// LedBar constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public LedBar(GrovePi grovePi, GrovePort port) : this(grovePi, port, LedBarOrientation.GreenToRed) { }
/// <summary> /// Relay constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> /// <param name="inverted">If inverted, the relay is on when output is low and off when output is high</param> public Relay(GrovePi grovePi, GrovePort port, bool inverted) : base(grovePi, port) { IsInverted = inverted; }
internal AccelerometerSensor(GrovePi device, Pin pin) { if (device == null) throw new ArgumentNullException(nameof(device)); _device = device; _pin = pin; }
internal UltrasonicRangerSensor(GrovePi device, Pin pin) { _device = device; _pin = pin; }
/// <summary> /// Potentiometer sensor constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public PotentiometerSensor(GrovePi grovePi, GrovePort port) : base(grovePi, port) { }
/// <summary> /// Button constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public Button(GrovePi grovePi, GrovePort port) : base(grovePi, port) { }
/// <summary> /// Light sensor constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public LightSensor(GrovePi grovePi, GrovePort port) : base(grovePi, port) { }
/// <summary> /// Relay constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public Relay(GrovePi grovePi, GrovePort port) : this(grovePi, port, false) { }
/// <summary> /// SoundSensor constructor /// </summary> /// <param name="grovePi">The GoPiGo3 class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public SoundSensor(GrovePi grovePi, GrovePort port) : base(grovePi, port) { }
/// <summary> /// Led constructor /// </summary> /// <param name="grovePi">The GrovePi class</param> /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param> public Led(GrovePi grovePi, GrovePort port) : base(grovePi, port) { }
internal FourDigitDisplay(GrovePi device, Pin pin) { if (device == null) throw new ArgumentNullException(nameof(device)); _device = device; _pin = pin; }