Hello
I need some help to write a code for oled display. where it should display mode 0 for few seconds once it is connected then it should change to mode 1....5 with the touch button.
here is what I did but it is not working:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int TouchButton = 16;
int counter = 0;
void setup() {
pinMode(TouchButton, INPUT);
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// init done
oled.clearDisplay(); // clear display
oled.setTextSize(1); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(0, 0); // position to display
}
void loop(){
int touchState = digitalRead(TouchButton); // read new state
if(touchState == HIGH) {
counter ++; //Reset count if over max mode number
delay(2000);
oled.clearDisplay();
oled.display();
if(counter == 7) {
counter = 0;
}
}
switch (counter) {
case 1: //switch to mode 0
oled.println("Mode 0"); // text to display
oled.display(); // show on OLED
break;
case 2:
oled.println("Mode 1"); // text to display
oled.display(); // show on OLED
break;
case 3:
oled.println("Mode 2"); // text to display
oled.display(); // show on OLED
break;
case 4:
oled.println("Mode 3"); // text to display
oled.display(); // show on OLED
break;
case 5:
oled.println("Mode 4"); // text to display
oled.display(); // show on OLED
break;
case 6:
oled.println("Mode 5"); // text to display
oled.display(); // show on OLED
break;
}
}