annotate service/busyboxArduino/main.ino @ 963:2decd45addf4

notes on pins Ignore-this: 1fced0c832715c5fbd16011563e7120a darcs-hash:20150120053811-312f9-cbcd7801cd4a454a3ae4a05c5534cfb0a9cbafb8
author drewp <drewp@bigasterisk.com>
date Mon, 19 Jan 2015 21:38:11 -0800
parents 70fd4c07a326
children 4c62b6d416a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
963
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
1 /*
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
2 D0 <---------
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
3 D1 lcd rw
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
4 D2 <---------
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
5 D3 ir out -----
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
6 D4 lcd 4
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
7 D5 lcd 5
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
8 D6 lcd 6
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
9 D7 lcd 7
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
10 D8 lcd rs
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
11 D9 lcd en
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
12 D10 lcd backlight
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
13 D11 tbd <------------
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
14 D12 motion in <--------
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
15 D13 debug led <--------
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
16
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
17 */
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
18 #include <Arduino.h>
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
19 #include <LiquidCrystal.h>
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
20 #include "DFR_Key.h"
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
21 #include "IRremote.h"
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
22
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
23 // see http://www.dfrobot.com/image/data/DFR0009/LCDKeypad%20Shield%20V1.0%20SCH.pdf
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
24 #define I2C_ADDR 0x27 // I2C address of PCF8574A
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
25 #define BACKLIGHT_PIN 10
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
26 #define En_pin 9
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
27 #define Rw_pin 1
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
28 #define Rs_pin 8
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
29 #define D4_pin 4
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
30 #define D5_pin 5
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
31 #define D6_pin 6
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
32 #define D7_pin 7
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
33
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
34 LiquidCrystal lcd(Rs_pin, Rw_pin, En_pin, D4_pin, D5_pin, D6_pin, D7_pin, BACKLIGHT_PIN, POSITIVE);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
35 DFR_Key keypad;
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
36
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
37 #define debugLed 13
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
38
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
39 byte backlightStandard = 0;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
40 byte backlightCurrent = 0;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
41 byte backlightKeypressBoost = 30;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
42
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
43 int lastKey = -1;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
44 int lastUnsentKeydown = -1;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
45 uint16_t steps = 0;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
46 uint16_t stepDelayPerBrightnessFade = 2048;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
47
963
2decd45addf4 notes on pins
drewp <drewp@bigasterisk.com>
parents: 962
diff changeset
48 // uses pin 3
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
49 IRsend irsend;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
50
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
51 void sendnec(byte addr, byte cmd) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
52 uint32_t w = 0x00ff0000;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
53 w |= (cmd << 8) & 0xff00;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
54 w |= (~cmd) & 0xff;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
55 irsend.sendNEC(w, 32);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
56 delay(100);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
57 }
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
58
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
59 void setup(void) {
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
60 pinMode(debugLed, OUTPUT);
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
61 Serial.begin(115200);
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
62 keypad.setRate(10);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
63 lcd.begin(16,2);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
64
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
65
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
66 for (int i = 0; i < 1; i++) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
67 digitalWrite(debugLed,1);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
68 /*
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
69 44 key remote. command chart: http://blog.allgaiershops.com/2012/05/
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
70 Up Down Play Pwr
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
71 0x3A 0xBA 0x82 0x02
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
72
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
73 Red Grn Blu Wht
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
74 1A 9A A2 22
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
75
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
76 2A AA 92 12
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
77
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
78 0A 8A B2 32
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
79
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
80 38 B8 78 F8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
81
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
82 18 98 58 D8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
83
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
84 RUp GUp BUp Quick
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
85 28 A8 68 E8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
86
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
87 RDn GDn BDn Slow
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
88 08 88 48 C8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
89
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
90 DIY1 DIY2 DIY3 AUTO
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
91 30 B0 70 F0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
92
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
93 DIY4 DIY5 DIY6 Flash
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
94 10 90 50 D0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
95
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
96 JMP3 JMP7 Fade Fade7
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
97 20 A0 60 E0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
98
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
99 irsend.sendNEC(0xff0002fd, 32);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
100 irsend.sendNEC(0x00ff02fd, 32);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
101 irsend.sendNEC(0x00ff40bf, 32);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
102 irsend.sendNEC(0xff0040bf, 32);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
103 */
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
104 delay(100);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
105
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
106 // LED618 remote command byte (addr is ff)
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
107 // see https://github.com/alistairallan/RgbIrLed/blob/master/RgbIrLed.cpp#L44
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
108 #define ON 0xE0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
109 #define OFF 0x60
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
110 #define BRIGHTNESS_UP 0xA0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
111 #define BRIGHTNESS_DOWN 0x20
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
112 #define FLASH 0xF0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
113 #define STROBE 0xE8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
114 #define FADE 0xD8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
115 #define SMOOTH 0xC8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
116
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
117 #define RED 0x90
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
118 #define GREEN 0x10
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
119 #define BLUE 0x50
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
120 #define WHITE 0xD0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
121
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
122 #define ORANGE 0xB0
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
123 #define YELLOW_DARK 0xA8
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
124 #define YELLOW_MEDIUM 0x98
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
125 #define YELLOW_LIGHT 0x88
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
126
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
127 #define GREEN_LIGHT 0x30
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
128 #define GREEN_BLUE1 0x28
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
129 #define GREEN_BLUE2 0x18
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
130 #define GREEN_BLUE3 0x08
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
131
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
132 #define BLUE_RED 0x70
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
133 #define PURPLE_DARK 0x68
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
134 #define PURPLE_LIGHT 0x58
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
135 #define PINK 0x48
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
136 sendnec(0xff, ON);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
137
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
138 digitalWrite(debugLed,0);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
139 delay(100);
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
140 }
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
141 }
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
142
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
143
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
144 void loop() {
962
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
145 while (Serial.available() <= 2) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
146 int localKey = keypad.getKey();
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
147 if (localKey != SAMPLE_WAIT) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
148 if (localKey != lastKey) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
149 if (lastKey == 0) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
150 backlightCurrent = min(255, backlightStandard +
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
151 backlightKeypressBoost);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
152 lastUnsentKeydown = localKey;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
153 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
154 lastKey = localKey;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
155 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
156 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
157
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
158 if (backlightCurrent > backlightStandard) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
159 steps++;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
160 if (steps % stepDelayPerBrightnessFade == 0) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
161 backlightCurrent--;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
162 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
163 } else if (backlightCurrent < backlightStandard) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
164 backlightCurrent = backlightStandard;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
165 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
166 lcd.setBacklight(backlightCurrent);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
167 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
168 byte i = Serial.read();
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
169 if (i != 0x60) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
170 return;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
171 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
172 i = Serial.read(); // command
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
173 if (i == 0) { // get status
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
174 Serial.print('{');
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
175 if (lastUnsentKeydown != -1) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
176 Serial.print("\"keyDown\":");
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
177 Serial.print(lastUnsentKeydown);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
178 Serial.print(",");
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
179 lastUnsentKeydown = -1;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
180 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
181 Serial.print("\"slider1\":"); Serial.print(analogRead(1));
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
182 Serial.print(",\"slider2\":"); Serial.print(analogRead(2));
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
183 Serial.print(",\"slider3\":"); Serial.print(analogRead(3));
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
184 Serial.print(",\"slider4\":"); Serial.print(analogRead(4));
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
185 Serial.print("}\n");
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
186 } else if (i == 1) { // write text
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
187 while (Serial.available() < 3) NULL;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
188 byte row = Serial.read();
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
189 byte col = Serial.read();
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
190 byte nchars = Serial.read();
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
191 char buf[32];
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
192 char *p=buf;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
193 while (nchars--) {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
194 while (Serial.available() < 1) NULL;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
195 *(p++) = Serial.read();
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
196 }
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
197 *p = 0;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
198 lcd.setCursor(row, col);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
199 lcd.print(buf);
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
200 } else if (i == 2) { // set backlight
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
201 while (Serial.available() < 1) NULL;
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
202 backlightStandard = Serial.read();
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
203 } else {
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
204 // unknown command
70fd4c07a326 busybox py and arduino
drewp <drewp@bigasterisk.com>
parents: 958
diff changeset
205 }
958
f83d494b0f31 start buttons+lcd program
drewp <drewp@bigasterisk.com>
parents:
diff changeset
206 }