#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//define OLED parameters
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH,SCREEN_HEIGHT,&Wire,OLED_RESET);
//buttons
int buttonPin1=17; //active high
int buttonPin2=16; //active low
void setup() {
//display intialization
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(1000);
display.clearDisplay();
print_line("Hello",0,0,2);
delay(1000);
print_line("World!",0,20,2);
delay(1000);
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
//intialize the digital pins as input
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int buttonState1=digitalRead(buttonPin1);
int buttonState2=digitalRead(buttonPin2);
if(buttonState1==HIGH){
Serial.println("Button is pressed ACTIVE HIGH");
delay(200); //Debounce
}
if(buttonState2==LOW){
Serial.println("Button is pressed ACTIVE LOW");
delay(200); //Debounce
}
//delay(10); // this speeds up the simulation
}
void print_line(String text, int column,int row, int text_size){
display.setTextSize(text_size); // Set text size
display.setTextColor(SSD1306_WHITE); // Set text color
display.setCursor(column,row); // Set cursor position
display.println(text); //Print text
display.display(); //Update the display
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306