public static void ShiftOut( IDigitalWriteRead dwr, int dataPin, int clockPin, int val, BitOrder bitOrder = BitOrder.MSBFIRST) { int i; System.Diagnostics.Debug.WriteLine("Shift {0}", val); for (i = 0; i < 8; i++) { if (bitOrder == BitOrder.LSBFIRST) { var a = (val & (1 << i)); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(a)); } else { var b = (val & (1 << (7 - i))); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(b)); } ClockIt(dwr, clockPin); } }
static void GpioSample(IDigitalWriteRead gpios, bool oneLoopOnly = false) { var goOn = true; const int waitTime = 65; while (goOn) { for (var i = 0; i < gpios.MaxGpio; i++) { gpios.DigitalWrite(i, PinState.High); Thread.Sleep(waitTime); } Thread.Sleep(waitTime); for (var i = 0; i < gpios.MaxGpio; i++) { gpios.DigitalWrite(i, PinState.Low); Thread.Sleep(waitTime); } Thread.Sleep(waitTime); if (System.Console.KeyAvailable) { var k = System.Console.ReadKey(); if (k.Key == ConsoleKey.Q) { goOn = false; } } if (oneLoopOnly) { goOn = false; } } }
public static void ShiftOut(IDigitalWriteRead dwr, int dataPin, int clockPin, List <byte> vals, BitOrder bitOrder = BitOrder.MSBFIRST) { foreach (var val in vals) { ShiftOut(dwr, dataPin, clockPin, val, bitOrder); } }
public GenericButton(IDigitalWriteRead digitalWriteRead, int gpioIndex, bool inverse = false) { this._gpioIndex = gpioIndex; this._digitalWriteRead = digitalWriteRead; this._inverse = inverse; this._digitalWriteRead.SetPinMode(gpioIndex, PinMode.Input); }
public Relay(IDigitalWriteRead _digitalWriteRead, int gpioPin) { this._gpioPin = gpioPin; this._digitalWriteRead = _digitalWriteRead; this._state = PinState.Unknown; this.TurnOff(); }
public MotionSensorPIR(IDigitalWriteRead digitalWriteRead, int gpio, int resetTimeInSecond = 4) { this._idleStartTime = DateTime.UtcNow; this._gpio = gpio; this._resetTimeInSecond = resetTimeInSecond; this._digitalWriteRead = digitalWriteRead; _digitalWriteRead.SetPullUp(gpio, PinState.High); _digitalWriteRead.SetPinMode(gpio, PinMode.Input); }
public static async Task Blink(IDigitalWriteRead gpios, int pin = 4, int times = 1000, int delay = 500) { for (int i = 0; i < times; i++) { gpios.DigitalWrite(pin, PinState.High); await Task.Delay(delay); gpios.DigitalWrite(pin, PinState.Low); await Task.Delay(delay); } }
public Potentiometer(IDigitalWriteRead digitalWriteRead, int inPin, int outPin, int minCalibratedValue, int maxCalibratedValue, int sampleFrequencySeconds = 500, bool reversePercentageValue = false, int timeOutMaxValue = 2000) { this._timeOut = new TimeOut(sampleFrequencySeconds); this._inPin = inPin; this._outPin = outPin; this._digitalWriteRead = digitalWriteRead; this._minCalibratedValue = minCalibratedValue; this._maxCalibratedValue = maxCalibratedValue; this._rangeCalibratedValue = maxCalibratedValue - minCalibratedValue; this._timeOutMaxValue = timeOutMaxValue; this._reversePercentageValue = reversePercentageValue; this._digitalWriteRead.SetPinMode(_outPin, PinMode.Output); }
public static void ShiftOutDataClockOptimized(IDigitalWriteRead dwr, int dataPin, int clockPin, int val, BitOrder bitOrder = BitOrder.MSBFIRST) { int i; for (i = 0; i < 8; i++) { if (bitOrder == BitOrder.LSBFIRST) { var a = (val & (1 << i)); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(a)); } else { var b = (val & (1 << (7 - i))); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(b)); } ClockIt(dwr, clockPin); } }
public static void ShiftOutDataClockOptimized(IDigitalWriteRead dwr, int dataPin , int clockPin, int val, SB bitOrder = SB.MSBFIRST) { int i; for (i = 0; i < 8; i++) { if (bitOrder == SB.LSBFIRST) { var a = (val & (1 << i)); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(a)); } else { var b = (val & (1 << (7 - i))); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(b)); } ClockIt(dwr, clockPin); } }
void Init(IDigitalWriteRead digitalWriteRead, uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) { // Detect if the digitalWriteRead implementation is a real Nusbio rather than an gpio extender for Nusbio. // With Nusbio we can use some of the hardware acceleration to send the data if (digitalWriteRead is Nusbio) { this.Nusbio = digitalWriteRead as Nusbio; } _rs_pin = rs; _rw_pin = rw; _enable_pin = enable; _data_pins[0] = d0; _data_pins[1] = d1; _data_pins[2] = d2; _data_pins[3] = d3; _data_pins[4] = d4; _data_pins[5] = d5; _data_pins[6] = d6; _data_pins[7] = d7; this.SetPinMode(_rs_pin, MadeInTheUSB.GPIO.PinMode.Output); // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# if (_rw_pin != 255) { SetPinMode(_rw_pin, MadeInTheUSB.GPIO.PinMode.Output); } SetPinMode(_enable_pin, MadeInTheUSB.GPIO.PinMode.Output); if (fourbitmode > 0) { _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; } else { _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; } Begin(16, 1); }
public static int ShiftIn(IDigitalWriteRead dwr, int dataPin, int clockPin, BitOrder bitOrder) { int value = 0; int i; for (i = 0; i < 8; ++i) { dwr.DigitalWrite(clockPin, PinState.High); if (bitOrder == BitOrder.LSBFIRST) { value |= Nusbio.ConvertTo1Or0(dwr.DigitalRead(dataPin)) << i; } else { value |= Nusbio.ConvertTo1Or0(dwr.DigitalRead(dataPin)) << (7 - i); } dwr.DigitalWrite(dataPin, PinState.Low); } return(value); }
public LiquidCrystal(IDigitalWriteRead digitalWriteRead, uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3): base(digitalWriteRead) { Init(digitalWriteRead, 1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); }
public LiquidCrystal(IDigitalWriteRead digitalWriteRead, uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7): base(digitalWriteRead) { Init(digitalWriteRead, 0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); }
public Apds9660GestureSensor(II2C device, IDigitalWriteRead gpio = null, int?interruptPin = null) { Device = device; Gpio = gpio; InterruptPin = interruptPin; }
public DigitalMotionSensorPIR(IDigitalWriteRead digitalWriteRead, NusbioGpio gpio, int resetTimeInSecond = 4) : this(digitalWriteRead, int.Parse(gpio.ToString().Replace("Gpio", "")), resetTimeInSecond) { }
public LiquidCrystal(IDigitalWriteRead digitalWriteRead, uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) : base(digitalWriteRead) { Init(digitalWriteRead, 1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); }
public LiquidCrystal(IDigitalWriteRead digitalWriteRead, uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) : base(digitalWriteRead) { Init(digitalWriteRead, 0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); }
//protected Nusbio _nusbio; public LiquidCrystalBase(IDigitalWriteRead digitalWriteRead) { _DigitalWriteRead = digitalWriteRead; }
public static void ClockIt(IDigitalWriteRead dwr, int clockPin) { dwr.DigitalWrite(clockPin, PinState.High); dwr.DigitalWrite(clockPin, PinState.Low); }
void Init(IDigitalWriteRead digitalWriteRead, uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) { // Detect if the digitalWriteRead implementation is a real Nusbio rather than an gpio extender for Nusbio. // With Nusbio we can use some of the hardware acceleration to send the data if(digitalWriteRead is Nusbio) { this.Nusbio = digitalWriteRead as Nusbio; } _rs_pin = rs; _rw_pin = rw; _enable_pin = enable; _data_pins[0] = d0; _data_pins[1] = d1; _data_pins[2] = d2; _data_pins[3] = d3; _data_pins[4] = d4; _data_pins[5] = d5; _data_pins[6] = d6; _data_pins[7] = d7; this.SetPinMode(_rs_pin, MadeInTheUSB.GPIO.PinMode.Output); // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# if (_rw_pin != 255) { SetPinMode(_rw_pin, MadeInTheUSB.GPIO.PinMode.Output); } SetPinMode(_enable_pin, MadeInTheUSB.GPIO.PinMode.Output); if (fourbitmode > 0) _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; Begin(16, 1); }
public static int ShiftIn(IDigitalWriteRead dwr, int dataPin, int clockPin, SB bitOrder) { int value = 0; int i; for (i = 0; i < 8; ++i) { dwr.DigitalWrite(clockPin, PinState.High); if (bitOrder == SB.LSBFIRST) value |= Nusbio.ConvertTo1Or0(dwr.DigitalRead(dataPin)) << i; else value |= Nusbio.ConvertTo1Or0(dwr.DigitalRead(dataPin)) << (7 - i); dwr.DigitalWrite(dataPin, PinState.Low); } return value; }