Hey if anyone can help me that would be super! I just want to know if anybody can help me can rearrange this code so it will NOT toggle but show the word "Danger" on the OLED when pinbutton 2 has been connected to ground and have the OLED go blank once pinbutton 2 has no connection to ground. But if you cant rearrange this code to work can you just give me a simple code that will make words appear momentarily on a oled i2c when a push button has been pressed?
heres the code:
// Adafruit-GFX-Library - Version: Latest
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
// Adafruit_SSD1306 - Version: Latest
#include <Adafruit_SSD1306.h>
int sensorPin = A0; // select the input pin for ldr
int sensorValue = 0;
bool toggle = false;
int buttonpin;
#define OLED_RESET 4 // not used / nicht genutzt bei diesem Display
Adafruit_SSD1306 display(OLED_RESET);
char inChar;
String string;
void setup() {
pinMode(13, OUTPUT);
buttonpin = 2;
pinMode(buttonpin, INPUT_PULLUP);
// initialize with the I2C addr 0x3C / mit I2C-Adresse 0x3c initialisieren
display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
Serial.begin(9600);
display.clearDisplay();
display.display();
delay(2000);
display.clearDisplay();
display.setTextColor(INVERSE);
}
void loop()
{
if (digitalRead(buttonpin) == LOW)
{
toggle = !toggle;
while(digitalRead(buttonpin) == LOW);
}
switch( toggle )
{
case 1:
display.clearDisplay();
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
display.setCursor(41,20);
display.setTextSize(1);
display.print("");
display.setCursor(32,20);
display.setTextSize(0);
display.print("D a n g e r");
delay(500);
break;
case 0:
display.clearDisplay();
break;
}
display.display();
}