#include <LiquidCrystal_I2C.h>
int ledPin = 0;
int buttonPin = 1;
int buttonState = 0;
int lastButtonState = 0;
int lcdSDAPin = 26;
int lcdSCL = 21;
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// Initialize serial communication at 115200 bits per second
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
pinMode(ledPin, OUTPUT);
// Set the button pin as input with an internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
// Init
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
}
void loop() {
turnOnLEDOnButtonPress();
}
void turnOnLEDOnButtonPress() {
// Read the current state of the button
buttonState = digitalRead(buttonPin);
// If the button state has changed
if (buttonState != lastButtonState) {
// Print the new state
if (buttonState == LOW) {
Serial1.println("Button pressed");
digitalWrite(ledPin, HIGH);
} else {
Serial1.println("Button released");
digitalWrite(ledPin, LOW);
}
// Update the last button state
lastButtonState = buttonState;
// Small delay to debounce the button
delay(50);
}
}