#include <LiquidCrystal.h>
#include <hardware/gpio.h>
#include <ArduinoJson.h>
const char* triviaData = "{\"question\": \"The capital of India is Delhi\", \"answer\": \"true\"},\n{\"question\": \"Tamil is best language \", \"answer\": \"true\"}";
// String fruits[4] = {"apple", "banana", "orange", "grape"};
const int buttonPin = 14; // Change to the GPIO pin you used for the button
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int buttonState = 0; // Variable to store the button reading
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging (optional)
lcd.begin(16, 2);
lcd.print("Quiz Game");
// lcd.setCursor(2, 1);
// lcd.print("> Pi Pico <");
pinMode(buttonPin, INPUT); // Set the button pin as an input
}
void loop() {
// char json[] = "{\"Q2\":\"The\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
char json[] = "{\"Q2\":\"Tamil is best language \",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
// char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
JsonDocument doc;
deserializeJson(doc, json);
// const char* q2 = doc["Q2"];
String q2 = "This is running text";
const char* sensor = doc["sensor"];
const char* q02 = doc["Q2"];
long time = doc["time"];
double latitude = doc["data"][0];
double longitude = doc["data"][1];
Serial.println(q02);
// Serial.println(sensor);
// Serial.println(time);
lcd.setCursor(2, 1);
// lcd.print(sensor);
// lcd.print(time);
////////////////////////
delay(500);
//////////////////
buttonState = digitalRead(buttonPin); // Read the button state
int textPosition = 0;
if (buttonState == LOW) {
delay(500);
lcd.clear();
// Shift the text by one position
String shiftedText = q2.substring(textPosition) + q2.substring(0, textPosition);
// Print the shifted text
lcd.print(shiftedText);
lcd.print(q02);
delay(250); // Adjust delay for desired speed
textPosition++;
// Reset text position if it goes off screen
if (textPosition >= q2.length()) {
textPosition = 0;
}
// lcd.print("test");
// lcd.setCursor(1, 1); // Set cursor to the beginning of the first line
// lcd.print(fruits[0]); // Print the first fruit ("apple")
// lcd.print(fruits[0]); // Print the first element ("apple")
// If button is pressed (LOW means pressed)
// lcd.clear(); // Clear the LCD display
// }
// delay(5); // Small delay to avoid bouncing (adjust as needed)
}
}
//////////////////////