changeset 3:19ea19d8381a default tip

Add a service button for controlling display
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Tue, 25 Aug 2015 17:23:55 +0200
parents 13a554ba5332
children
files voter.ino
diffstat 1 files changed, 26 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/voter.ino	Tue Aug 25 13:49:49 2015 +0200
+++ b/voter.ino	Tue Aug 25 17:23:55 2015 +0200
@@ -13,16 +13,15 @@
     0b01101111,
 };
 const unsigned char SYMBOLS[] = {
-    0b01011111,
-    0b01111100,
-    0b01011000,
+    0b00000001,
+    0b01000000,
+    0b00001000,
 };
 const int BUTTON_PINS[] = {2, 3, A2};
 const int LED_PINS[] = {A3, A4, A5};
-
+const int BUTTON_PIN = 1;
 
 int counts[] = {0, 0, 0};
-long int last = 0;
 
 
 void show7seg(int number, int symbol) {
@@ -52,8 +51,9 @@
 
 
 void handle_buttons() {
+    static long int last = 0;
+    long int now = millis();
     static bool led = false;
-    long int now = millis();
 
     if (now - last < 400) {
         // Debouncing.
@@ -75,6 +75,24 @@
     }
 }
 
+void handle_display() {
+    static long int last = 0;
+    static int counter = 0;
+    long int now = millis();
+
+    if (now - last < 5000) {
+        show7seg(counts[counter], counter);
+    }
+    if (now - last < 400) {
+        // Debouncing.
+        return;
+    }
+
+    if (!digitalRead(BUTTON_PIN)) {
+        last = now;
+        counter = (counter + 1) % 3;
+    }
+}
 
 void setup() {
     for (int s = 0; s < 8; ++s) {
@@ -89,14 +107,11 @@
     for (int l = 0; l < 3; ++l) {
         pinMode(LED_PINS[l], OUTPUT);
     }
+    pinMode(BUTTON_PIN, INPUT_PULLUP);
 }
 
 
 void loop() {
-    long int now = millis();
-    int counter = (now / 2000) % 3;
     handle_buttons();
-    if (now - last < 30000) {
-        show7seg(counts[counter], counter);
-    }
+    handle_display();
 }