#include #include #include "Bounce.h" void setup(); void loop(); #define BUFFER_SIZE 64 char buf[BUFFER_SIZE]; // initialize the library with the numbers of the interface pins #ifdef ENERGIA LiquidCrystal lcd(13, 12, 10, 9, 8, 7); #else LiquidCrystal lcd(12, 11, 10, 9, 8, 7); #endif // indices: 0 = prev; 1 = pause; 2 = next #ifdef ENERGIA byte buttons[] = {15, 6, 5}; #else byte buttons[] = {A0, A1, A2}; #endif #define NUMBUTTONS sizeof(buttons) #define DEBOUNCE 10 Bounce bounce_buttons[NUMBUTTONS]; void setup() { byte i; lcd.begin(16, 2); // The usb chip hangs if it tries to send data and no-one listens // so we give the client time to start up first #ifdef ENERGIA lcd.print("Waiting ..."); for (int i = 0; i < 20; i++) { lcd.setCursor(0, 1); lcd.print("Serial: "); lcd.print(i); lcd.print("/20"); delay(1000); } lcd.setCursor(0,0); lcd.clear(); #endif Serial.begin(9600); Serial.setTimeout(5000); for (i = 0; i < NUMBUTTONS; i++) { pinMode(buttons[i], INPUT_PULLUP); bounce_buttons[i] = Bounce(buttons[i], DEBOUNCE); } Serial.println("ready"); lcd.print("Serial ready"); } bool button_just_pressed(int i) { bounce_buttons[i].update(); return bounce_buttons[i].fallingEdge(); } void loop() { if (button_just_pressed(0)) { Serial.println("previous"); } if (button_just_pressed(1)) { Serial.println("pause"); } if (button_just_pressed(2)) { Serial.println("next"); } // output what we got over serial if (Serial.available() >= 32) { lcd.setCursor(0, 0); Serial.readBytes(buf, 32); for (int i = 0; i < 32; i++) { if (i == 16) { lcd.setCursor(0, 1); } lcd.write(buf[i]); } } }