public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { Cls(nusbio); var sr = new ShiftRegister74HC595(nusbio, dataPin, latchPin, clockPin); sr.Send8BitValue(0); while (nusbio.Loop()) { if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { break; } if (k == ConsoleKey.A) { sr.AnimateOneLeftToRightAndRightToLeft(15); } } } } Console.Clear(); }
public static void GpioAnimatioOneAtTheTime(Nusbio nusbio, ShiftRegister74HC595 sr, int waitTime, bool demoGpio3to7Too = false) { // Gpio 0,1,2 are used to control the 2 shift register 74HC595, but we can use the other 5 sr.SetGpioMask(ShiftRegister74HC595.ExGpio.None); for (int i = 0; i < sr.MaxGpio; i++) { var g = sr.GetGpioFromIndex(i + sr.MinGpioIndex); Console.WriteLine(g); sr.SetGpioMask(g); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } for (int i = sr.MaxGpio - 1; i >= 0; i--) { var g = sr.GetGpioFromIndex(i + sr.MinGpioIndex); Console.WriteLine(g); sr.SetGpioMask(g); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } sr.SetGpioMask(0); Thread.Sleep(waitTime * 10); }
/// <summary> /// Constructor using bit banging /// </summary> /// <param name="interfaceDataMode">Interface data mode</param> /// <param name="rs">Pin Register Select</param> /// <param name="rw">Pin Select Read/Write</param> /// <param name="enable">Pin Enable</param> /// <param name="ds">Pin Serial Data</param> /// <param name="shcp">Pin Shift Register Clock</param> /// <param name="stcp">Pin Storage Register Clock</param> /// <param name="mr">Pin Master Reset</param> /// <param name="oe">Pin Output Enable</param> /// <param name="bitOrder">Bit order during transferring</param> public Shift74HC595LcdTransferProvider(InterfaceDataMode interfaceDataMode, Cpu.Pin rs, Cpu.Pin rw, Cpu.Pin enable, Cpu.Pin ds, Cpu.Pin shcp, Cpu.Pin stcp, Cpu.Pin mr, Cpu.Pin oe, BitOrder bitOrder) { // set interface data mode (4 or 8 bits) this.interfaceDataMode = interfaceDataMode; // Register Select (rs) pin is necessary if (rs == Cpu.Pin.GPIO_NONE) { throw new ArgumentException("Register Select (RS) pin is necessary"); } this.rsPort = new OutputPort(rs, false); // you can save 1 pin setting from your board, wiring RW pin to GND for write only operation if (rw != Cpu.Pin.GPIO_NONE) { this.rwPort = new OutputPort(rw, false); } // Enable (enable) pin is necessary if (enable == Cpu.Pin.GPIO_NONE) { throw new ArgumentException("Enable (EN) signal pin is necessary"); } this.enablePort = new OutputPort(enable, false); this.shift = new ShiftRegister74HC595(ds, shcp, stcp, mr, oe, bitOrder); }
public static void TestSetting16bitAtOnce(Nusbio nusbio, ShiftRegister74HC595 sr, int waitTime) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct() + " 16 bit value demo", ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.Gotoxy(0, 3); //sr.TestPins(); sr.Reset(); var p1 = 1; var p2 = 256; for (var i = 0; i < 8; i++) { sr.SetGpioMask(p1 + p2); //sr.SetDataLinesAndAddrLines((byte)p1, (byte)(p2 >> 8)); //sr.SetGpioMask((byte)p1, (byte)(p2 >> 8)); Console.WriteLine("16 bite value:{0:000000} - {1} {2}", p1 + p2, MadeInTheUSB.WinUtil.BitUtil.BitRpr(p1), MadeInTheUSB.WinUtil.BitUtil.BitRpr(p2 >> 8) ); Thread.Sleep(waitTime); p1 *= 2; p2 *= 2; } Console.WriteLine("---"); Thread.Sleep(waitTime); sr.SetGpioMask(0); p1 = 1; p2 = 256; var pp1 = p1; var pp2 = p2; for (var i = 0; i < 8; i++) { //sr.SetGpioMask(pp1 + pp2); sr.SetGpioMask((byte)pp1, (byte)(pp2 >> 8)); Console.WriteLine("16 bite value:{0:000000} - {1} {2}", pp1 + pp2, MadeInTheUSB.WinUtil.BitUtil.BitRpr(pp1), MadeInTheUSB.WinUtil.BitUtil.BitRpr(pp2 >> 8) ); Thread.Sleep(waitTime); p1 *= 2; p2 *= 2; pp1 += p1; pp2 += p2; } Console.WriteLine("Hit any key to continue"); Console.ReadKey(); sr.SetGpioMask(0); }
static void Cls(Nusbio nusbio, ShiftRegister74HC595 sr) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 4, string.Format("Extended Gpio Count:{0}, StartIndex:{1}, EndIndex:{2}", sr.MaxGpio, sr.MinGpioIndex, sr.MaxGpioIndex), ConsoleColor.Black, ConsoleColor.DarkCyan); ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); ConsoleEx.WriteMenu(-1, 2, "1) Program for 0..15 counter"); ConsoleEx.WriteMenu(-1, 4, "Q)uit"); }
public LedMS88SR74HC595(ShiftRegister74HC595 shiftreg) : this(shiftreg, new[] { new OutputPort(Pins.GPIO_PIN_D0, true), new OutputPort(Pins.GPIO_PIN_D1, true), new OutputPort(Pins.GPIO_PIN_D2, true), new OutputPort(Pins.GPIO_PIN_D3, true), new OutputPort(Pins.GPIO_PIN_D4, true), new OutputPort(Pins.GPIO_PIN_D5, true), new OutputPort(Pins.GPIO_PIN_D6, true), new OutputPort(Pins.GPIO_PIN_D7, true) }) { }
public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } // Set to 8 if only using 1 Shift Register 74HC595 const int MAX_EXTENDED_GPIO = 16; //Nusbio.BaudRate = Nusbio.FastestBaudRate / 512; using (var nusbio = new Nusbio(serialNumber)) { var sr = new ShiftRegister74HC595(nusbio, MAX_EXTENDED_GPIO, dataPin, latchPin, clockPin); Cls(nusbio, sr); sr.Reset(); while (nusbio.Loop()) { if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { break; } if (k == ConsoleKey.D1) { GpioDemo(nusbio, sr); } if (k == ConsoleKey.D2) { GpioDemo(nusbio, sr, demoGpio3to7Too: true); } if (k == ConsoleKey.D3) { TestSetting16bitAtOnce(nusbio, sr, 400); } Cls(nusbio, sr); } } } Console.Clear(); }
public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } const int MAX_EXTENDED_GPIO = 16; using (var nusbio = new Nusbio(serialNumber)) { var sr = new ShiftRegister74HC595(nusbio, MAX_EXTENDED_GPIO, dataPin, latchPin, clockPin); Cls(nusbio, sr); sr.Reset(); var e = new MadeInTheUSB.EEPROM.EEPROM_AT28C16( nusbio, sr, // address line extra gpio 8,9,10,11,12 (5 bit for address range of 0..32) // data line extra gpio 16,17,18,19,20,21,22,23 writeEnable: NusbioGpio.Gpio7, outputEnable: NusbioGpio.Gpio6 ); while (nusbio.Loop()) { if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { break; } if (k == ConsoleKey.D1) { ProgramFor0To15Counter(nusbio, e); } Cls(nusbio, sr); } } } Console.Clear(); }
private static void GpioDemo(Nusbio nusbio, ShiftRegister74HC595 sr, bool demoGpio3to7Too = false) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct() + " Gpio 16 Demo", ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.Gotoxy(0, 3); int wait = 150; while (true) { GpioAnimation(nusbio, sr, wait, demoGpio3to7Too); if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Q) { break; } } }
public EEPROM_AT28C16(Nusbio nusbio, ShiftRegister74HC595 sr, NusbioGpio writeEnable, NusbioGpio outputEnable) { this._writeEnable = writeEnable; this._outputEnable = outputEnable; this._nusbio = nusbio; this._sr = sr; // Just used as a place holder we will really use gpio 8,9,10,11,12 this._addressLines = new List <NusbioGpio>() { NusbioGpio.Gpio0, NusbioGpio.Gpio1, NusbioGpio.Gpio2, NusbioGpio.Gpio3, NusbioGpio.Gpio4 }; _nusbio[this._writeEnable].High(); // Disable _nusbio[this._outputEnable].Low(); // Enable }
public static void GpioAnimation(Nusbio nusbio, ShiftRegister74HC595 sr, int waitTime, bool demoGpio3to7Too = false) { // Gpio 0,1,2 are used to control the 2 shift register 74HC595, but we can use the other 5 var nusbioGpioLeft = new List <NusbioGpio>() { NusbioGpio.Gpio3, NusbioGpio.Gpio4, NusbioGpio.Gpio5, NusbioGpio.Gpio6, NusbioGpio.Gpio7, }; sr.SetGpioMask(ShiftRegister74HC595.ExGpio.None); if (!demoGpio3to7Too) { GpioAnimatioOneAtTheTime(nusbio, sr, waitTime, demoGpio3to7Too); } if (demoGpio3to7Too) // Demo internal nusbio gpio 3..7 also { for (int i = 0; i < nusbioGpioLeft.Count; i++) { nusbio[nusbioGpioLeft[i]].DigitalWrite(PinState.High); Console.WriteLine(nusbioGpioLeft[i]); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } } for (int i = 0; i < sr.GetGpioEnums().Count; i++) { sr.DigitalWrite(i + sr.MinGpioIndex, PinState.High); Console.WriteLine(sr.GpioStates); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } for (int i = sr.GetGpioEnums().Count - 1; i >= 0; i--) { sr.DigitalWrite(i + sr.MinGpioIndex, PinState.Low); Console.WriteLine(sr.GpioStates); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } if (demoGpio3to7Too) { for (int i = nusbioGpioLeft.Count - 1; i >= 0; i--) { nusbio[nusbioGpioLeft[i]].DigitalWrite(PinState.Low); Console.WriteLine(nusbioGpioLeft[i]); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } } sr.SetGpioMask(0); }
public LedMS88SR74HC595(ShiftRegister74HC595 shiftreg, OutputPort[] rowPorts) { ShiftRegister = shiftreg; RowPortMap = rowPorts; }