//OLED
#include <Wire.h>
#include <U8g2lib.h>
//Select the option that matches the dimensions of the OLED
U8G2_SSD1306_128X64_NONAME_F_HW_I2C DISPA(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//Pins for SDA and SCL
#define SDA 4
#define SCL 5
//Pin numbers
int LED = D9;
int BUTTON1 = D10; //abajo (cerca de OLED)
int BUTTON2 = D8; //arriba
bool program = true;
//---------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
//LED
pinMode(LED, OUTPUT);
//SDA and SCL pinout
pinMode(SDA, OUTPUT);
pinMode(SCL, OUTPUT);
// Set I2C bus speed on board and both displays
Wire.setClock(100000);
DISPA.setBusClock(100000);
//Set I2C Adress (0x78/0x7A, or 0x3C/0x3D)
DISPA.setI2CAddress(0x78);
//Turn on OLED and get it ready to accept data
DISPA.begin();
//Select a font
DISPA.setFont(u8g2_font_logisoso16_tf );
//Make sure the display buffer is clear
DISPA.clearBuffer();
//Interrupt pinmode
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(BUTTON2, INPUT_PULLUP);
//Interrupt config
attachInterrupt(digitalPinToInterrupt(BUTTON1), programT, FALLING);
attachInterrupt(digitalPinToInterrupt(BUTTON2), programF, FALLING);
}
//---------------------------------------------------------------------------------
void loop() {
while(program == true){ //BUTTON1 D8 (abajo)
//LED
digitalWrite(LED, HIGH);
DISPA.clearBuffer();
DISPA.setCursor(30, 20); //(X,Y)
DISPA.print("Program A");
DISPA.sendBuffer(); //Command to show things on display
}
while(program == false){ //BUTTON2 D10 (arriba)
//LED
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
DISPA.clearBuffer();
DISPA.setCursor(30, 20); //(X,Y)
DISPA.print("Program B");
DISPA.sendBuffer(); //Command to show things on display
}
}
//---------------------------------------------------------------------------------
void programT(){
program = true;
}
void programF(){
program = false;
}