PageRenderTime 92ms CodeModel.GetById 81ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/LCDButtons/examples/ShowButtons/ShowButtons.ino

https://bitbucket.org/jraedler/lcdbuttons
Arduino Sketch | 65 lines | 56 code | 9 blank | 0 comment | 0 complexity | 4c23645e4ef8c43042502e28656f6596 MD5 | raw file
 1#include <LiquidCrystal.h>
 2#include <LCDButtons.h>
 3
 4/* test the functionality of LCDButtons:
 5 * - button presses are shown in line 1 for one secons
 6 * - SELECT toggles the waiting for releasing the button
 7 * - UP and DOWN change the delay time between repeated readings (5-200 ms)
 8 */
 9
10LCDButtons lcd;
11
12boolean wait;
13byte    repeatDelay;
14
15
16void changeParameters() {
17  char s[17];
18  lcd.setButtonParameter(wait, repeatDelay);
19  lcd.setCursor(0,1);
20  snprintf(s, 16, "%s - %03d", (wait) ? "   WAIT": "NO WAIT", repeatDelay);
21  lcd.print(s);
22}
23
24
25void setup() {
26  lcd.begin(16, 2);
27  lcd.clear();
28  lcd.setCursor(0, 0);
29  lcd.print("PRESS ANY KEY");
30  wait = 1;
31  repeatDelay = 5;
32  changeParameters();
33}
34
35
36void loop() {
37  static byte button;
38  button = lcd.button();
39  if (button > 0) {
40    lcd.setCursor(0, 0);
41    switch (button) {
42      case BUTTON_SELECT:
43        lcd.print("SELECT       ");
44        wait = ! wait;
45        changeParameters();
46        break;
47      case BUTTON_LEFT:
48        lcd.print("LEFT         ");
49        break;
50      case BUTTON_RIGHT:
51        lcd.print("RIGHT        ");
52        break;
53      case BUTTON_UP:
54        lcd.print("UP           ");
55        repeatDelay = min(repeatDelay+5, 200);
56        changeParameters();
57        break;
58      case BUTTON_DOWN:
59        lcd.print("DOWN         ");
60        repeatDelay = max(repeatDelay-5, 5);
61        changeParameters();
62        break;
63    }
64  }
65}