i put full my effort but i cant be successfull
i have 4 kinds of mode in my project
i want showing the word mode1 at the first on display without press any button
by pressing buttonPin = 8; mode 1 replace to mode 2 and by clicking again change to mode 3 and 4 and by clicking again turn back to mode 1
please edit my sKetch I am not very familiar with arduino coding
thanks
this is my scetch
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Adafruit_SH1106.h>
const int buttonPin = 8; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 4; // previous state of the button
const byte OLED_RESET = 4; // not used / nicht genutzt bei diesem Display
Adafruit_SH1106 display(OLED_RESET);
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
display.begin(SH1106_SWITCHCAPVCC, 0x3c);
Serial.begin(9600);
display.clearDisplay();
display.display();
delay(2000);
display.clearDisplay();
display.setTextColor(INVERSE);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonPushCounter == 1) {
buttonPushCounter++;
{
display.clearDisplay();
display.setCursor(32,20);
display.setTextSize(0);
display.print("MODE1");
}
} else {
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by checking the modulo of the
// button push counter. the modulo function gives you the remainder of the
// division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}