Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 119 lines (94 sloc) 2.556 kB
9be2451 @nottwo Add top-like StatusMonitor example
authored
1 /*
2 * StatusMonitor
3 *
4 * Displays formatted, dynamic, real-time Arduino status information
5 * using BasicTerm.
6 *
7 * It responds to the following input commands:
8 * ' ' (space): Toggle LED
7d25d27 @nottwo Use character escape instead of literal ^L
authored
9 * '\f' (Ctrl-L): Redraw screen
9be2451 @nottwo Add top-like StatusMonitor example
authored
10 */
11
12 #include <BasicTerm.h>
13
14 BasicTerm term(&Serial);
15
16 #define LED 13
17
33d48a8 @nottwo Change storage for now & last to uint32_t
authored
18 uint32_t now;
19 uint32_t last;
9be2451 @nottwo Add top-like StatusMonitor example
authored
20
21 void setup(void) {
22 Serial.begin(9600);
23
24 pinMode(LED, OUTPUT);
25
26 uint8_t i;
27
28 for(i = A0; i <= A5; i++) {
29 pinMode(i, INPUT);
30 }
31
32 for(i = 2; i <= 12; i++) {
33 pinMode(i, INPUT);
34 }
35
36 digitalWrite(LED, LOW);
37
38 term.init();
39 term.cls();
40 term.show_cursor(false);
41
42 now = millis();
43
44 }
45
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
46 #define DIGITAL_ROW 3
47 #define ANALOG_ROW 7
9be2451 @nottwo Add top-like StatusMonitor example
authored
48
49 void loop(void) {
50 uint8_t i = 0;
51 uint16_t key;
52
53 last = now;
54 now = millis();
55
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
56 term.position(0, 0);
827309d @nottwo Decorate display with attributes & color
authored
57 term.set_attribute(BT_NORMAL);
58 term.set_attribute(BT_BOLD);
8c8f9b8 @nottwo Use tabs for intraline spacing
authored
59 term.print(F("Arduino Status Monitor\t"));
9be2451 @nottwo Add top-like StatusMonitor example
authored
60
827309d @nottwo Decorate display with attributes & color
authored
61 term.set_attribute(BT_NORMAL);
5b8ef21 @nottwo Store static strings in PROGMEM
authored
62 term.print(F("Current millis: "));
9be2451 @nottwo Add top-like StatusMonitor example
authored
63 term.print(now);
8c8f9b8 @nottwo Use tabs for intraline spacing
authored
64 term.print(F("\tmillis since last loop: "));
827309d @nottwo Decorate display with attributes & color
authored
65 term.set_attribute(BT_UNDERLINE);
9be2451 @nottwo Add top-like StatusMonitor example
authored
66 term.print(now - last);
827309d @nottwo Decorate display with attributes & color
authored
67 term.set_attribute(BT_NORMAL);
9be2451 @nottwo Add top-like StatusMonitor example
authored
68
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
69 term.position(1, 0);
5b8ef21 @nottwo Store static strings in PROGMEM
authored
70 term.print(F("LED "));
827309d @nottwo Decorate display with attributes & color
authored
71 term.set_color(BT_GREEN, BT_BLACK);
9be2451 @nottwo Add top-like StatusMonitor example
authored
72 if(digitalRead(LED) == HIGH) {
827309d @nottwo Decorate display with attributes & color
authored
73 term.set_attribute(BT_BOLD | BT_UNDERLINE);
5b8ef21 @nottwo Store static strings in PROGMEM
authored
74 term.print(F("ON "));
9be2451 @nottwo Add top-like StatusMonitor example
authored
75 } else {
5b8ef21 @nottwo Store static strings in PROGMEM
authored
76 term.print(F("OFF"));
9be2451 @nottwo Add top-like StatusMonitor example
authored
77 }
827309d @nottwo Decorate display with attributes & color
authored
78 term.set_attribute(BT_NORMAL);
9be2451 @nottwo Add top-like StatusMonitor example
authored
79
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
80 term.position(DIGITAL_ROW, 0);
5b8ef21 @nottwo Store static strings in PROGMEM
authored
81 term.print(F("Digital Readings"));
9be2451 @nottwo Add top-like StatusMonitor example
authored
82
83 for(i = 0; i <= 13; i++) {
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
84 term.position(DIGITAL_ROW + 1, (i)*6);
827309d @nottwo Decorate display with attributes & color
authored
85 term.set_attribute(BT_NORMAL);
9be2451 @nottwo Add top-like StatusMonitor example
authored
86 term.print("DIN");
87 term.print(i);
827309d @nottwo Decorate display with attributes & color
authored
88 term.set_color(BT_RED, BT_BLACK);
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
89 term.position(DIGITAL_ROW + 2, (i)*6);
9be2451 @nottwo Add top-like StatusMonitor example
authored
90 term.print(digitalRead(i));
91 }
92
827309d @nottwo Decorate display with attributes & color
authored
93 term.set_attribute(BT_NORMAL);
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
94 term.position(ANALOG_ROW, 0);
5b8ef21 @nottwo Store static strings in PROGMEM
authored
95 term.print(F("Analog Readings"));
9be2451 @nottwo Add top-like StatusMonitor example
authored
96
97 for(i = A0; i <= A5; i++) {
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
98 term.position(ANALOG_ROW + 1, (i-A0)*6);
827309d @nottwo Decorate display with attributes & color
authored
99 term.set_attribute(BT_NORMAL);
5b8ef21 @nottwo Store static strings in PROGMEM
authored
100 term.print(F("AIN"));
9be2451 @nottwo Add top-like StatusMonitor example
authored
101 term.print(i - A0);
827309d @nottwo Decorate display with attributes & color
authored
102 term.set_color(BT_MAGENTA, BT_BLACK);
e82e1f8 @nottwo Update examples to use (0,0) origin
authored
103 term.position(ANALOG_ROW + 2, (i-A0)*6);
9be2451 @nottwo Add top-like StatusMonitor example
authored
104 term.print(analogRead(i));
105 }
106
107 key = term.get_key();
108 switch(key) {
109 case ' ':
110 /* Spacebar: toggle LED */
111 digitalWrite(LED, !digitalRead(LED));
112 break;
7d25d27 @nottwo Use character escape instead of literal ^L
authored
113 case '\f':
9be2451 @nottwo Add top-like StatusMonitor example
authored
114 /* Ctrl-L: redraw screen */
115 term.cls();
116 break;
117 }
118 }
Something went wrong with that request. Please try again.