Hi,
I would to create a simple application to show on display the state o button but I do not know how to do it
This is my code
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
const int ledpin = 6;
const int interruptPin = 2;
volatile boolean ledOn = false;
void setup(void)
{
pinMode (ledpin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin),function1, FALLING);
delay(1000); // wait a second
// initialize the SSD1306 OLED display with I2C address = 0x3D
display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
// clear the display buffer.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(20, 0);
display.print("button");
display.setCursor(15, 15);
display.print(ledOn);
display.display(); // update the display
display.setTextSize(1); // text size = 1
}
void loop() {
}
void function1()
{
if (ledOn)
{
ledOn = false;
digitalWrite(ledpin, LOW);
delay (200);
}
else
{
ledOn = true;
digitalWrite(ledpin, HIGH);
delay (200);
}
}
// end of code.