#include "pico/stdlib.h"
#include "i2c-display-lib.hpp"
// Define the GPIO pin for the button
const uint buttonPin = 10; // You can change this to your desired GPIO pin number
void printIntToDisplay(int num) {
// Temporary buffer to hold the integer as a string
char buffer[20];
snprintf(buffer, sizeof(buffer), "%d", num); // Convert integer to string
i2cdisplay::print(buffer); // Print the string
}
bool isButtonPressed() {
return gpio_get(buttonPin) == 0; // Return true if button is pressed, false otherwise
}
int main() {
i2cdisplay::init(6, 7); // SDA and SCL
// Initialize the button GPIO pin
gpio_init(buttonPin);
gpio_set_dir(buttonPin, GPIO_IN);
gpio_pull_up(buttonPin);
// Display initial messages
i2cdisplay::home();
i2cdisplay::clear();
i2cdisplay::print("Hello World!");
sleep_ms(2000); // Display for 2 seconds
i2cdisplay::clear();
i2cdisplay::setCursor(0, 0);
i2cdisplay::print("How are you?");
sleep_ms(2000); // Display for 2 seconds
// Start counter
int counter = 0; // Counter variable
while (true) {
i2cdisplay::clear();
i2cdisplay::home();
i2cdisplay::print("Counter: ");
printIntToDisplay(counter); // Display the counter value
// Check if the button is pressed to stop the counter
if (!isButtonPressed()) {
counter++; // Increment the counter if the button is not pressed
}
sleep_ms(1000);
}
}