public static void Main(string[] args) { Console.WriteLine("Hello Ssd1306 Sample!"); #if SSD1327 using (Ssd1327 device = GetSsd1327WithI2c()) { Initialize(device); ClearScreen(device); //SendMessage(device, "Hello .NET IoT!"); SendMessage(device, DisplayIpAddress()); } #else using (Ssd1306 device = GetSsd1306WithI2c()) { Initialize(device); ClearScreen(device); // SendMessage(device, "Hello .NET IoT!!!"); // SendMessage(device, DisplayIpAddress()); DisplayImages(device); DisplayClock(device); ClearScreen(device); } #endif }
private static void SendMessage(Ssd1327 device, string message) { device.SetRowAddress(0x00, 0x07); foreach (char character in message) { byte[] charBitMap = BasicFont.GetCharacterBytes(character); List <byte> data = new List <byte>(); for (var i = 0; i < charBitMap.Length; i = i + 2) { for (var j = 0; j < 8; j++) { byte cdata = 0x00; int bit1 = (byte)((charBitMap[i] >> j) & 0x01); cdata |= (bit1 == 1) ? (byte)0xF0 : (byte)0x00; var secondBitIndex = i + 1; if (secondBitIndex < charBitMap.Length) { int bit2 = (byte)((charBitMap[i + 1] >> j) & 0x01); cdata |= (bit2 == 1) ? (byte)0x0F : (byte)0x00; } data.Add(cdata); } } device.SendData(data.ToArray()); } }
void Initialize() { Console.WriteLine("Initialize display..."); var spiBus = Device.CreateSpiBus(); display = new Ssd1327(Device, spiBus, Device.Pins.D02, Device.Pins.D01, Device.Pins.D00); display.SetContrast(60); graphics = new GraphicsLibrary(display); graphics.CurrentFont = new Font8x12(); Console.WriteLine("Initialize led..."); onboardLed = new RgbPwmLed(device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue, 3.3f, 3.3f, 3.3f, Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode); }
// Display size 96x96. private static void Initialize(Ssd1327 device) { device.SendCommand(new Ssd1327Cmnds.SetUnlockDriver(true)); device.SendCommand(new SetDisplayOff()); device.SendCommand(new SetMultiplexRatio(0x5F)); device.SendCommand(new Ssd1327Cmnds.SetDisplayStartLine()); device.SendCommand(new Ssd1327Cmnds.SetDisplayOffset(0x5F)); device.SendCommand(new Ssd1327Cmnds.SetReMap()); device.SendCommand(new Ssd1327Cmnds.SetInternalVddRegulator(true)); device.SendCommand(new SetContrastControlForBank0(0x53)); device.SendCommand(new Ssd1327Cmnds.SetPhaseLength(0X51)); device.SendCommand(new Ssd1327Cmnds.SetDisplayClockDivideRatioOscillatorFrequency(0x01, 0x00)); device.SendCommand(new Ssd1327Cmnds.SelectDefaultLinearGrayScaleTable()); device.SendCommand(new Ssd1327Cmnds.SetPreChargeVoltage(0x08)); device.SendCommand(new Ssd1327Cmnds.SetComDeselectVoltageLevel(0X07)); device.SendCommand(new Ssd1327Cmnds.SetSecondPreChargePeriod(0x01)); device.SendCommand(new Ssd1327Cmnds.SetSecondPreChargeVsl(true)); device.SendCommand(new Ssd1327Cmnds.SetNormalDisplay()); device.SendCommand(new DeactivateScroll()); device.SendCommand(new SetDisplayOn()); device.SendCommand(new Ssd1327Cmnds.SetRowAddress()); device.SendCommand(new Ssd1327Cmnds.SetColumnAddress()); }
private static void ClearScreen(Ssd1327 device) { device.ClearDisplay(); }