public async Task Init() { _factory.Init(); var lcd = _factory.GetComponent <ILCD_Hitatchi_I2C>(); //We got the pin config from here: //https://arduino-info.wikispaces.com/LCD-Blue-I2C //You'll have to find your own mapping for your device! await lcd.Init(0x27, 16, 2, LCDConstants.LCD_5x8DOTS, 2, 1, 0, 4, 5, 6, 7, 3, BacklightPolarity.Positive); for (int i = 0; i < 3; i++) { lcd.BackLight(); StopwatchDelay.Delay(100); lcd.NoBacklight(); StopwatchDelay.Delay(100); } lcd.NoCursor(); lcd.BackLight(); lcd.Home(); lcd.SetCursor(0, 0); //Start at character 4 on line 0 lcd.Write("FT232H, LCD, C#"); StopwatchDelay.Delay(250); lcd.SetCursor(0, 1); lcd.Write("git.io/vmEdE"); }
public void CreateChar(int location, int[] charMap) { location &= 0x7; // we only have 8 locations 0-7 _command(LCDConstants.SetCGRAMAddr | (location << 3)); StopwatchDelay.DelayMicroSeconds(30); for (int i = 0; i < 8; i++) { Write(charMap[i]); // call the virtual write method StopwatchDelay.DelayMicroSeconds(40); } }
public void Home() { _command(LCDConstants.ReturnHome); StopwatchDelay.DelayMicroSeconds(LCDConstants.HomeClearExec); }
public void Clear() { _command(LCDConstants.ClearDisplay); StopwatchDelay.DelayMicroSeconds(LCDConstants.HomeClearExec); }
public virtual async Task Begin(int cols, int rows, int charSize = LCDConstants.LCD_5x8DOTS) { if (rows > 1) { _displayFunction |= LCDConstants.LCD_2LINE; } _numlines = rows; _cols = cols; StopwatchDelay.Delay(100); if ((_displayFunction & LCDConstants.LCD_8BITMODE) == 0) { // this is according to the hitachi HD44780 datasheet // figure 24, pg 46 // we start in 8bit mode, try to set 4 bit mode Send(0x03, LCDConstants.FOUR_BITS); StopwatchDelay.DelayMicroSeconds(4500); // wait min 4.1ms // second try Send(0x03, LCDConstants.FOUR_BITS); StopwatchDelay.DelayMicroSeconds(4500); // wait min 4.1ms // third go! Send(0x03, LCDConstants.FOUR_BITS); StopwatchDelay.DelayMicroSeconds(150); // finally, set to 4-bit interface Send(0x02, LCDConstants.FOUR_BITS); } else { // this is according to the hitachi HD44780 datasheet // page 45 figure 23 // Send function set command sequence _command(LCDConstants.FunctionSet | _displayFunction); StopwatchDelay.DelayMicroSeconds(4500); // wait more than 4.1ms // second try _command(LCDConstants.FunctionSet | _displayFunction); StopwatchDelay.DelayMicroSeconds(150); // third go _command(LCDConstants.FunctionSet | _displayFunction); } // finally, set # lines, font size, etc. _command(LCDConstants.FunctionSet | _displayFunction); // turn the display on with no cursor or blinking default _displaycontrol = LCDConstants.DisplayOn | LCDConstants.CursorOff | LCDConstants.BlinkOff; Display(); // clear the LCD Clear(); // Initialize to default text direction (for romance languages) _displaymode = LCDConstants.EntryLeft | LCDConstants.ShiftDecrement; // set the entry mode _command(LCDConstants.EntryModeSet | _displaymode); BackLight(); }
private const int LatencyTimer = 255; // Hz static void Main(string[] args) { List <int[]> charBitmap = new List <int[]> { new int[] { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 }, new int[] { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 }, new int[] { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 }, new int[] { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 }, new int[] { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 }, new int[] { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 }, new int[] { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 }, new int[] { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 } }; var lcd = new I2CLCD(0x27, 2, 1, 0, 4, 5, 6, 7, 3, BacklightPolarity.Positive); lcd.Begin(16, 2); //for (int i = 0; i < charBitmap.Count; i++) //{ // lcd.CreateChar(i, charBitmap[i]); //} for (int i = 0; i < 3; i++) { lcd.BackLight(); StopwatchDelay.Delay(100); lcd.NoBacklight(); StopwatchDelay.Delay(100); } lcd.BackLight(); lcd.Home(); lcd.SetCursor(0, 0); //Start at character 4 on line 0 lcd.Write("FT232H, LCD, C#"); StopwatchDelay.Delay(250); lcd.SetCursor(0, 1); lcd.Write("git.io/vmEdE"); //var rn = new Random((int)DateTime.Now.Ticks); //while (true) //{ // lcd.Home(); // // Do a little animation by writing to the same location // for (int i = 0; i < 2; i++) // { // for (int j = 0; j < 16; j++) // { // lcd.Write((char)(rn.Next(7))); // } // lcd.SetCursor(0, 1); // } // StopwatchDelay.Delay(200); //} //var start = 0x21; //var end = 0x28; //for (var address = start; address < end; address++) //{ // Console.WriteLine(address); // var lcd = new I2CLCD(address, 2, 1, 0, 4, 5, 6, 7, 3, BacklightPolarity.Positive); // lcd.Begin(16, 2); // //for (int i = 0; i < 3; i++) // //{ // // lcd.BackLight(); // // StopwatchDelay.Delay(250); // // lcd.NoBacklight(); // // StopwatchDelay.Delay(250); // //} // lcd.BackLight(); // lcd.SetCursor(0, 0); //Start at character 4 on line 0 // lcd.Write("Hello, world!"); // StopwatchDelay.Delay(250); // lcd.SetCursor(0, 1); // lcd.Write("HI!YourDuino.com"); //} Console.WriteLine("Finished"); //var adcSpiConfig = new FtChannelConfig //{ // ClockRate = ConnectionSpeed, // LatencyTimer = LatencyTimer, // configOptions = FtConfigOptions.Mode0 | FtConfigOptions.CsDbus3 | FtConfigOptions.CsActivelow //}; // var c = new I2CDevice(adcSpiConfig); //var b = new byte[1]; //b[0] = 0x02; //int transferred; //var result = c.Write(0x27, b, 0, out transferred, FtI2CTransferOptions.FastTransfer); Console.Read(); // Debug.WriteLine(result); return; //var adcConfig = new Maxim186Configuration // { // Channel = Maxim186.Channel.Channel0, // ConversionType = Maxim186.ConversionType.SingleEnded, // Polarity = Maxim186.Polarity.Unipolar, // PowerMode = Maxim186.PowerMode.InternalClockMode // }; //var adc = new Maxim186(adcConfig, adcSpiConfig); //do //{ // Console.WriteLine(adc.GetConvertedSample()); //} while (true); //*/ }