We can add a display that is useful for debugging or displaying information as our program runs.
Make these connections between the microcontroller and the display board
[ ] GND to ground
[ ] VCC to 5 volts
[ ] SCL to D13 on the microcontroller, this is our clock line
[ ] SDA to D11 on the microcontroller, this is our data line
[ ] RES to D8 on the microcontroller, this is reset
[ ] DC to D9 on the microcontroller, this indicates a data or command message
Here is a program we can use that includes the LED sequencer we made earlier, and combines it with a message on the display that shows which LED should currently be lit.
/* da Vinci Coders LED sequencer with display */
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, 13, 11, 10, 9, 8);
void setup() {
u8g2.begin();
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
int position;
char infostr[] = "Lighting LED 0";
void loop()
{
digitalWrite(position + 2, HIGH);
delay(400);
u8g2.firstPage();
do
{
u8g2.setFont(u8g2_font_ncenB10_tr);
infostr[13] = 49 + position;
u8g2.drawStr(0, 24, infostr);
} while (u8g2.nextPage());
digitalWrite(position + 2, LOW);
delay(400);
position = position + 1;
if (position > 3)
{
position = 0;
}
}