diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-01-16 21:43:28 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-01-16 21:43:28 +0100 |
commit | f6c2485f49613617605474ba7ef2a78471ba1fd0 (patch) | |
tree | 6cc1da1fdedbf0eb0e79ff6882c5c26157577fa6 /src/main.cpp | |
download | mpd-box-f6c2485f49613617605474ba7ef2a78471ba1fd0.tar.gz mpd-box-f6c2485f49613617605474ba7ef2a78471ba1fd0.tar.xz |
initial commit
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..30f2b87 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,65 @@ +#include <Arduino.h> +#include <LiquidCrystal.h> +#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 +LiquidCrystal lcd(12, 11, 10, 9, 8, 7); + +// A0 = prev; A1 = pause; A2 = next +byte buttons[] = {A0, A1, A2}; +#define NUMBUTTONS sizeof(buttons) +#define DEBOUNCE 10 +Bounce bounce_buttons[NUMBUTTONS]; + +void setup() { + byte i; + lcd.begin(16, 2); + Serial.begin(9600); + Serial.setTimeout(5000); + + for (i = 0; i < NUMBUTTONS; i++) { + pinMode(buttons[i], INPUT); + digitalWrite(buttons[i], HIGH); + bounce_buttons[i] = Bounce(buttons[i], DEBOUNCE); + } + + Serial.println("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]); + } + } +} + |