#include <SD.h>
#include <ezButton.h>
File file;
ezButton next(2);
ezButton prev(3);
ezButton select_book(4);
ezButton open_book(5);
// keeps track of which book is to be read
int book_num = 0;
int book_state = 0;
void setup()
{
Serial.begin(9600);
if (!SD.begin())
Serial.println("SD card not detected");
else
Serial.println("SD card detected");
// file = SD.open("harry.txt" , FILE_READ);
// Serial.print("Total Characters: ");
// Serial.println(file.size());
// if(file)
// {
// Serial.println("Harry Potter");
// delay(2000);
// while (file.available())
// {
// char data = file.read();
// Serial.print(data);
// }
// Serial.println();
// file.close();
// }
// Serial.println("File read successfully");
next.setDebounceTime(50);
prev.setDebounceTime(50);
select_book.setDebounceTime(50);
open_book.setDebounceTime(50);
}
void loop()
{
next.loop();
prev.loop();
select_book.loop();
open_book.loop();
if (next.isPressed())
book_num++;
else if (prev.isPressed())
book_num--;
// makes sure doesn't go past 0 or 1 as only 2 books present.
book_num = constrain(book_num,0,1);
//checks which book is selected
check_book();
}
void check_book()
{
if (book_num)
Serial.println("Think and Grow Rich!");
else
Serial.println("Harry Potter!");
}