#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// OLED dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
// Use I2C1 for GP26 (SDA) and GP27 (SCL)
Adafruit_SSD1306 display(
SCREEN_WIDTH,
SCREEN_HEIGHT,
&Wire1,
OLED_RESET
);
#define LED_PIN 5
#define BUTTON_PIN 2
void setup() {
Serial1.begin(115200);
delay(1000);
Serial1.println("Starting Pico...");
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
// Initialize I2C on GP26 and GP27
Wire1.setSDA(26);
Wire1.setSCL(27);
Wire1.begin();
Wire1.setClock(200000);
// Initialize OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial1.println("OLED initialization failed!");
while (true) {
delay(100);
}
}
Serial1.println("OLED initialized!");
// Display initial screen
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Pico is running");
display.println();
display.println("Button: RELEASED");
display.println("LED: OFF");
display.display();
}
void loop() {
bool buttonPressed = digitalRead(BUTTON_PIN) == LOW;
// Control LED
digitalWrite(LED_PIN, buttonPressed ? HIGH : LOW);
// Update OLED
display.clearDisplay();
display.setCursor(0, 0);
display.println("Pico is running");
display.println();
if (buttonPressed) {
display.println("Button: PRESSED");
display.println("LED: ON");
} else {
display.println("Button: RELEASED");
display.println("LED: OFF");
}
display.display();
delay(50);
}
Loading
ssd1306
ssd1306