neo_rad 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +112 -0
- data/License.txt +282 -0
- data/Manifest.txt +144 -0
- data/README.rdoc +1 -0
- data/Rakefile +142 -0
- data/bin/rad +302 -0
- data/lib/examples/add_hysteresis.rb +13 -0
- data/lib/examples/basic_blink.rb +10 -0
- data/lib/examples/blink_m_address_assignment.rb +104 -0
- data/lib/examples/blink_m_hello.rb +14 -0
- data/lib/examples/blink_m_multi.rb +61 -0
- data/lib/examples/blink_with_serial.rb +16 -0
- data/lib/examples/configure_pa_lcd_boot.rb +91 -0
- data/lib/examples/debounce_methods.rb +49 -0
- data/lib/examples/external_variable_fu.rb +26 -0
- data/lib/examples/external_variables.rb +32 -0
- data/lib/examples/first_sound.rb +23 -0
- data/lib/examples/frequency_generator.rb +30 -0
- data/lib/examples/hello_array.rb +48 -0
- data/lib/examples/hello_array2.rb +112 -0
- data/lib/examples/hello_array_eeprom.rb +59 -0
- data/lib/examples/hello_clock.rb +84 -0
- data/lib/examples/hello_eeprom.rb +51 -0
- data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
- data/lib/examples/hello_format_print.rb +94 -0
- data/lib/examples/hello_lcd_charset.rb +75 -0
- data/lib/examples/hello_pa_lcd.rb +59 -0
- data/lib/examples/hello_servos.rb +88 -0
- data/lib/examples/hello_spectra_sound.rb +38 -0
- data/lib/examples/hello_world.rb +11 -0
- data/lib/examples/hello_xbee.rb +12 -0
- data/lib/examples/hysteresis_duel.rb +39 -0
- data/lib/examples/i2c_with_clock_chip.rb +124 -0
- data/lib/examples/midi_beat_box.rb +86 -0
- data/lib/examples/midi_scales.rb +94 -0
- data/lib/examples/motor_knob.rb +30 -0
- data/lib/examples/servo_buttons.rb +23 -0
- data/lib/examples/servo_calibrate_continuous.rb +92 -0
- data/lib/examples/servo_throttle.rb +40 -0
- data/lib/examples/software_serial.rb +10 -0
- data/lib/examples/sparkfun_lcd.rb +48 -0
- data/lib/examples/spectra_soft_pot.rb +34 -0
- data/lib/examples/times_method.rb +8 -0
- data/lib/examples/toggle.rb +10 -0
- data/lib/examples/twitter.rb +57 -0
- data/lib/examples/two_wire.rb +14 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
- data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
- data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
- data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
- data/lib/libraries/DS1307/DS1307.cpp +162 -0
- data/lib/libraries/DS1307/DS1307.h +66 -0
- data/lib/libraries/DS1307/keywords.txt +18 -0
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
- data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
- data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
- data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
- data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
- data/lib/libraries/LoopTimer/keywords.txt +27 -0
- data/lib/libraries/OneWire/OneWire.cpp +194 -0
- data/lib/libraries/OneWire/OneWire.h +63 -0
- data/lib/libraries/OneWire/keywords.txt +35 -0
- data/lib/libraries/OneWire/readme.txt +13 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +296 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +69 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
- data/lib/libraries/Servo/Servo.cpp +192 -0
- data/lib/libraries/Servo/Servo.h +61 -0
- data/lib/libraries/Stepper/Stepper.cpp +220 -0
- data/lib/libraries/Stepper/Stepper.h +86 -0
- data/lib/libraries/Stepper/keywords.txt +28 -0
- data/lib/libraries/Wire/Wire.cpp +262 -0
- data/lib/libraries/Wire/Wire.h +67 -0
- data/lib/libraries/Wire/keywords.txt +31 -0
- data/lib/libraries/Wire/twi.h +57 -0
- data/lib/libraries/Wire/utility/twi.c +449 -0
- data/lib/libraries/Wire/utility/twi.h +57 -0
- data/lib/plugins/bitwise_ops.rb +54 -0
- data/lib/plugins/blink.rb +25 -0
- data/lib/plugins/blink_m.rb +356 -0
- data/lib/plugins/debounce.rb +138 -0
- data/lib/plugins/debug_output_to_lcd.rb +71 -0
- data/lib/plugins/hysteresis.rb +52 -0
- data/lib/plugins/input_output_state.rb +84 -0
- data/lib/plugins/lcd_padding.rb +58 -0
- data/lib/plugins/mem_test.rb +37 -0
- data/lib/plugins/midi.rb +60 -0
- data/lib/plugins/parallax_ping.rb +50 -0
- data/lib/plugins/servo_pulse.rb +31 -0
- data/lib/plugins/servo_setup.rb +86 -0
- data/lib/plugins/smoother.rb +54 -0
- data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
- data/lib/plugins/spectra_symbol.rb +79 -0
- data/lib/plugins/twitter_connect.rb +145 -0
- data/lib/rad/README.rdoc +5 -0
- data/lib/rad/arduino_plugin.rb +246 -0
- data/lib/rad/arduino_sketch.rb +628 -0
- data/lib/rad/darwin_installer.rb +23 -0
- data/lib/rad/generators/makefile/makefile.erb +243 -0
- data/lib/rad/generators/makefile/makefile.rb +38 -0
- data/lib/rad/hardware_library.rb +813 -0
- data/lib/rad/init.rb +15 -0
- data/lib/rad/linux_installer.rb +132 -0
- data/lib/rad/progressbar.rb +236 -0
- data/lib/rad/rad_processor.rb +128 -0
- data/lib/rad/rad_rewriter.rb +94 -0
- data/lib/rad/rad_type_checker.rb +26 -0
- data/lib/rad/sim/arduino_sketch.rb +57 -0
- data/lib/rad/sketch_compiler.rb +47 -0
- data/lib/rad/tasks/build_and_make.rake +210 -0
- data/lib/rad/tasks/rad.rb +2 -0
- data/lib/rad/todo.txt +13 -0
- data/lib/rad/variable_processing.rb +153 -0
- data/lib/rad/version.rb +9 -0
- data/lib/rad.rb +5 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/spec/examples/hello_world.rb +11 -0
- data/spec/examples/serial_motor.rb +12 -0
- data/spec/models/arduino_sketch_spec.rb +82 -0
- data/spec/models/sketch_compiler_spec.rb +96 -0
- data/spec/models/spec_helper.rb +2 -0
- data/spec/sim/hello_world_spec.rb +42 -0
- data/spec/spec.opts +1 -0
- data/test/hello_world_test/Makefile +436 -0
- data/test/hello_world_test/hello_world.cpp +23 -0
- data/test/test_array_processing.rb +179 -0
- data/test/test_plugin_loading.rb +151 -0
- data/test/test_translation_post_processing.rb +185 -0
- data/test/test_variable_processing.rb +238 -0
- data/website/examples/assembler_test.rb.html +73 -0
- data/website/examples/gps_reader.rb.html +39 -0
- data/website/examples/hello_world.rb.html +38 -0
- data/website/examples/serial_motor.rb.html +41 -0
- data/website/index.html +178 -0
- data/website/index.txt +64 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +169 -0
- data/website/template.rhtml +48 -0
- metadata +222 -0
@@ -0,0 +1,356 @@
|
|
1
|
+
class BlinkM < ArduinoPlugin
|
2
|
+
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# BlinkM_funcs.h -- Arduino library to control BlinkM
|
6
|
+
# --------------
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# Note: original version of this file lives with the BlinkMTester sketch
|
10
|
+
#
|
11
|
+
# 2007, Tod E. Kurt, ThingM, http://thingm.com/
|
12
|
+
#
|
13
|
+
# version: 20080203
|
14
|
+
#
|
15
|
+
# history:
|
16
|
+
# 20080101 - initial release
|
17
|
+
# 20080203 - added setStartupParam(), bugfix receiveBytes() from Dan Julio
|
18
|
+
# 20080727 - ported to rad jd barnhart
|
19
|
+
#
|
20
|
+
# first step, declare output pin 19 as i2c
|
21
|
+
## output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
|
22
|
+
|
23
|
+
|
24
|
+
include_wire
|
25
|
+
|
26
|
+
add_blink_m_struct
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
# Not needed when pin is declared with :enable => :true
|
31
|
+
# In fact, declaring it twice causes nothing but problems
|
32
|
+
|
33
|
+
static void BlinkM_begin()
|
34
|
+
{
|
35
|
+
Wire.begin(); // join i2c bus (address optional for master)
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
// General version of BlinkM_beginWithPower().
|
40
|
+
|
41
|
+
static void BlinkM_beginWithPowerPins(byte pwrpin, byte gndpin)
|
42
|
+
{
|
43
|
+
DDRC |= _BV(pwrpin) | _BV(gndpin); // make outputs
|
44
|
+
PORTC &=~ _BV(gndpin);
|
45
|
+
PORTC |= _BV(pwrpin);
|
46
|
+
delay(100); // wait for things to stabilize
|
47
|
+
|
48
|
+
Wire.begin();
|
49
|
+
}
|
50
|
+
|
51
|
+
// Call this first when BlinkM is plugged directly into Arduino
|
52
|
+
// The BlinkMs PWR (power) pins should line up with pins 2 and 3 of the connector,
|
53
|
+
// while the I2C (communications) pins should line up with pins 4 and 5.
|
54
|
+
|
55
|
+
static void BlinkM_beginWithPower()
|
56
|
+
{
|
57
|
+
BlinkM_beginWithPowerPins( PC3, PC2 );
|
58
|
+
}
|
59
|
+
|
60
|
+
// sends a generic command
|
61
|
+
|
62
|
+
static void BlinkM_sendCmd(byte addr, byte* cmd, int cmdlen)
|
63
|
+
{
|
64
|
+
Wire.beginTransmission(addr);
|
65
|
+
for( byte i=0; i<cmdlen; i++)
|
66
|
+
Wire.send(cmd[i]);
|
67
|
+
Wire.endTransmission();
|
68
|
+
}
|
69
|
+
|
70
|
+
// receives generic data
|
71
|
+
// returns 0 on success, and -1 if no data available
|
72
|
+
// note: responsiblity of caller to know how many bytes to expect
|
73
|
+
|
74
|
+
static int BlinkM_receiveBytes(byte addr, byte* resp, byte len)
|
75
|
+
{
|
76
|
+
Wire.requestFrom(addr, len);
|
77
|
+
if( Wire.available() ) {
|
78
|
+
for( int i=0; i<len; i++)
|
79
|
+
resp[i] = Wire.receive();
|
80
|
+
return 0;
|
81
|
+
}
|
82
|
+
return -1;
|
83
|
+
}
|
84
|
+
|
85
|
+
// Sets the I2C address of the BlinkM(s)
|
86
|
+
// Typically used to setup BlinkM addresses
|
87
|
+
// Connect one and call this with an address like 10,
|
88
|
+
// then 11 for the next and so on and so forth
|
89
|
+
// Uses "general call" broadcast address
|
90
|
+
|
91
|
+
static void BlinkM_setAddress(byte newaddress)
|
92
|
+
{
|
93
|
+
Wire.beginTransmission(0x00); // general call (broadcast address)
|
94
|
+
Wire.send('A');
|
95
|
+
Wire.send(newaddress);
|
96
|
+
Wire.send(0xD0);
|
97
|
+
Wire.send(0x0D); // dood!
|
98
|
+
Wire.send(newaddress);
|
99
|
+
Wire.endTransmission();
|
100
|
+
delay(50); // just in case
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
// Gets the I2C addrss of the BlinkM
|
105
|
+
// Kind of redundant when sent to a specific address
|
106
|
+
// but uses to verify BlinkM communication
|
107
|
+
|
108
|
+
static int BlinkM_getAddress(byte addr)
|
109
|
+
{
|
110
|
+
Wire.beginTransmission(addr);
|
111
|
+
Wire.send('a');
|
112
|
+
Wire.endTransmission();
|
113
|
+
Wire.requestFrom(addr, (byte)1);
|
114
|
+
if( Wire.available() ) {
|
115
|
+
byte b = Wire.receive();
|
116
|
+
return b;
|
117
|
+
}
|
118
|
+
return -1;
|
119
|
+
}
|
120
|
+
|
121
|
+
// Gets the BlinkM firmware version
|
122
|
+
|
123
|
+
static int BlinkM_getVersion(byte addr)
|
124
|
+
{
|
125
|
+
Wire.beginTransmission(addr);
|
126
|
+
Wire.send('Z');
|
127
|
+
Wire.endTransmission();
|
128
|
+
Wire.requestFrom(addr, (byte)2);
|
129
|
+
if( Wire.available() ) {
|
130
|
+
byte major_ver = Wire.receive();
|
131
|
+
byte minor_ver = Wire.receive();
|
132
|
+
return (major_ver<<8) + minor_ver;
|
133
|
+
}
|
134
|
+
return -1;
|
135
|
+
}
|
136
|
+
|
137
|
+
// Demonstrates how to verify you-re talking to a BlinkM
|
138
|
+
// and that you know its address -- message version
|
139
|
+
|
140
|
+
static char* blink_m_check_address_message(byte addr) // :as => :optional
|
141
|
+
{
|
142
|
+
char message[50];
|
143
|
+
char status[5];
|
144
|
+
strcpy(message, "received 0x");
|
145
|
+
//Serial.print("Checking BlinkM address...");
|
146
|
+
int b = BlinkM_getAddress(addr);
|
147
|
+
if( b==-1 ) {
|
148
|
+
//Serial.println("No response, that's not good");
|
149
|
+
return "No response, that's not good"; // no response
|
150
|
+
}
|
151
|
+
itoa(b, status ,16);
|
152
|
+
|
153
|
+
//Serial.print("received addr: 0x");
|
154
|
+
//Serial.print(b,HEX);
|
155
|
+
if( b != addr )
|
156
|
+
return "error, mismatch"; // error, addr mismatch
|
157
|
+
else
|
158
|
+
return strcat(message, status); // match, everything okay
|
159
|
+
}
|
160
|
+
|
161
|
+
// Demonstrates how to verify you-re talking to a BlinkM
|
162
|
+
// and that you know its address -- digital version
|
163
|
+
|
164
|
+
static int BlinkM_checkAddress(byte addr)
|
165
|
+
{
|
166
|
+
//Serial.print("Checking BlinkM address...");
|
167
|
+
int b = BlinkM_getAddress(addr);
|
168
|
+
if( b==-1 ) {
|
169
|
+
//Serial.println("No response, that's not good");
|
170
|
+
return -1; // no response
|
171
|
+
}
|
172
|
+
|
173
|
+
//Serial.print("received addr: 0x");
|
174
|
+
//Serial.print(b,HEX);
|
175
|
+
if( b != addr )
|
176
|
+
return 1; // error, addr mismatch
|
177
|
+
else
|
178
|
+
return 0; // match, everything okay
|
179
|
+
}
|
180
|
+
|
181
|
+
// Sets the speed of fading between colors.
|
182
|
+
// Higher numbers means faster fading, 255 == instantaneous fading
|
183
|
+
|
184
|
+
static void BlinkM_setFadeSpeed(byte addr, byte fadespeed)
|
185
|
+
{
|
186
|
+
Wire.beginTransmission(addr);
|
187
|
+
Wire.send('f');
|
188
|
+
Wire.send(fadespeed);
|
189
|
+
Wire.endTransmission();
|
190
|
+
}
|
191
|
+
|
192
|
+
// Sets the light script playback time adjust
|
193
|
+
// The timeadj argument is signed, and is an additive value to all
|
194
|
+
// durations in a light script. Set to zero to turn off time adjust.
|
195
|
+
|
196
|
+
static void BlinkM_setTimeAdj(byte addr, byte timeadj)
|
197
|
+
{
|
198
|
+
Wire.beginTransmission(addr);
|
199
|
+
Wire.send('t');
|
200
|
+
Wire.send(timeadj);
|
201
|
+
Wire.endTransmission();
|
202
|
+
}
|
203
|
+
|
204
|
+
// Fades to an RGB color
|
205
|
+
|
206
|
+
static void BlinkM_fadeToRGB(byte addr, byte red, byte grn, byte blu)
|
207
|
+
{
|
208
|
+
Wire.beginTransmission(addr);
|
209
|
+
Wire.send('c');
|
210
|
+
Wire.send(red);
|
211
|
+
Wire.send(grn);
|
212
|
+
Wire.send(blu);
|
213
|
+
Wire.endTransmission();
|
214
|
+
}
|
215
|
+
|
216
|
+
// Fades to an HSB color
|
217
|
+
|
218
|
+
static void BlinkM_fadeToHSB(byte addr, byte hue, byte saturation, byte brightness)
|
219
|
+
{
|
220
|
+
Wire.beginTransmission(addr);
|
221
|
+
Wire.send('h');
|
222
|
+
Wire.send(hue);
|
223
|
+
Wire.send(saturation);
|
224
|
+
Wire.send(brightness);
|
225
|
+
Wire.endTransmission();
|
226
|
+
}
|
227
|
+
|
228
|
+
// Sets an RGB color immediately
|
229
|
+
|
230
|
+
static void BlinkM_setRGB(byte addr, byte red, byte grn, byte blu)
|
231
|
+
{
|
232
|
+
Wire.beginTransmission(addr);
|
233
|
+
Wire.send('n');
|
234
|
+
Wire.send(red);
|
235
|
+
Wire.send(grn);
|
236
|
+
Wire.send(blu);
|
237
|
+
Wire.endTransmission();
|
238
|
+
}
|
239
|
+
|
240
|
+
// Fades to a random RGB color
|
241
|
+
|
242
|
+
static void BlinkM_fadeToRandomRGB(byte addr, byte rrnd, byte grnd, byte brnd)
|
243
|
+
{
|
244
|
+
Wire.beginTransmission(addr);
|
245
|
+
Wire.send('C');
|
246
|
+
Wire.send(rrnd);
|
247
|
+
Wire.send(grnd);
|
248
|
+
Wire.send(brnd);
|
249
|
+
Wire.endTransmission();
|
250
|
+
}
|
251
|
+
// Fades to a random HSB color
|
252
|
+
|
253
|
+
static void BlinkM_fadeToRandomHSB(byte addr, byte hrnd, byte srnd, byte brnd)
|
254
|
+
{
|
255
|
+
Wire.beginTransmission(addr);
|
256
|
+
Wire.send('H');
|
257
|
+
Wire.send(hrnd);
|
258
|
+
Wire.send(srnd);
|
259
|
+
Wire.send(brnd);
|
260
|
+
Wire.endTransmission();
|
261
|
+
}
|
262
|
+
|
263
|
+
static void BlinkM_getRGBColor(byte addr, byte* r, byte* g, byte* b)
|
264
|
+
{
|
265
|
+
Wire.beginTransmission(addr);
|
266
|
+
Wire.send('g');
|
267
|
+
Wire.endTransmission();
|
268
|
+
Wire.requestFrom(addr, (byte)3);
|
269
|
+
if( Wire.available() ) {
|
270
|
+
*r = Wire.receive();
|
271
|
+
*g = Wire.receive();
|
272
|
+
*b = Wire.receive();
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
static void BlinkM_playScript(byte addr, byte script_id, byte reps, byte pos)
|
277
|
+
{
|
278
|
+
Wire.beginTransmission(addr);
|
279
|
+
Wire.send('p');
|
280
|
+
Wire.send(script_id);
|
281
|
+
Wire.send(reps);
|
282
|
+
Wire.send(pos);
|
283
|
+
Wire.endTransmission();
|
284
|
+
}
|
285
|
+
|
286
|
+
static void BlinkM_stopScript(byte addr)
|
287
|
+
{
|
288
|
+
Wire.beginTransmission(addr);
|
289
|
+
Wire.send('o');
|
290
|
+
Wire.endTransmission();
|
291
|
+
}
|
292
|
+
|
293
|
+
static void BlinkM_setScriptLengthReps(byte addr, byte script_id,
|
294
|
+
byte len, byte reps)
|
295
|
+
{
|
296
|
+
Wire.beginTransmission(addr);
|
297
|
+
Wire.send('L');
|
298
|
+
Wire.send(script_id);
|
299
|
+
Wire.send(len);
|
300
|
+
Wire.send(reps);
|
301
|
+
Wire.endTransmission();
|
302
|
+
}
|
303
|
+
|
304
|
+
static void BlinkM_writeScriptLine(byte addr, byte script_id,
|
305
|
+
byte pos, byte dur,
|
306
|
+
byte cmd, byte arg1, byte arg2, byte arg3)
|
307
|
+
{
|
308
|
+
#ifdef BLINKM_FUNCS_DEBUG
|
309
|
+
Serial.print("writing line:"); Serial.print(pos,DEC);
|
310
|
+
Serial.print(" with cmd:"); Serial.print(cmd);
|
311
|
+
Serial.print(" arg1:"); Serial.println(arg1,HEX);
|
312
|
+
#endif
|
313
|
+
Wire.beginTransmission(addr);
|
314
|
+
Wire.send('W');
|
315
|
+
Wire.send(script_id);
|
316
|
+
Wire.send(pos);
|
317
|
+
Wire.send(dur);
|
318
|
+
Wire.send(cmd);
|
319
|
+
Wire.send(arg1);
|
320
|
+
Wire.send(arg2);
|
321
|
+
Wire.send(arg3);
|
322
|
+
Wire.endTransmission();
|
323
|
+
}
|
324
|
+
|
325
|
+
static void BlinkM_writeScript(byte addr, byte script_id,
|
326
|
+
byte len, byte reps,
|
327
|
+
blinkm_script_line* lines)
|
328
|
+
{
|
329
|
+
#ifdef BLINKM_FUNCS_DEBUG
|
330
|
+
Serial.print("writing script to addr:"); Serial.print(addr,DEC);
|
331
|
+
Serial.print(", script_id:"); Serial.println(script_id,DEC);
|
332
|
+
#endif
|
333
|
+
for(byte i=0; i < len; i++) {
|
334
|
+
blinkm_script_line l = lines[i];
|
335
|
+
BlinkM_writeScriptLine( addr, script_id, i, l.dur,
|
336
|
+
l.cmd[0], l.cmd[1], l.cmd[2], l.cmd[3]);
|
337
|
+
}
|
338
|
+
BlinkM_setScriptLengthReps(addr, script_id, len, reps);
|
339
|
+
}
|
340
|
+
|
341
|
+
|
342
|
+
static void BlinkM_setStartupParams(byte addr, byte mode, byte script_id,
|
343
|
+
byte reps, byte fadespeed, byte timeadj)
|
344
|
+
{
|
345
|
+
Wire.beginTransmission(addr);
|
346
|
+
Wire.send('B');
|
347
|
+
Wire.send(mode);
|
348
|
+
Wire.send(script_id);
|
349
|
+
Wire.send(reps);
|
350
|
+
Wire.send(fadespeed);
|
351
|
+
Wire.send(timeadj);
|
352
|
+
Wire.endTransmission();
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
class Debounce < ArduinoPlugin
|
2
|
+
|
3
|
+
|
4
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
5
|
+
# that may be added to the main setup method
|
6
|
+
# function prototypes not needed since we generate them automatically
|
7
|
+
|
8
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
9
|
+
# hack from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1209050315
|
10
|
+
|
11
|
+
# plugin_directives "#undef int", "#include <stdio.h>", "char _str[32];", "#define writeln(...) sprintf(_str, __VA_ARGS__); Serial.println(_str)"
|
12
|
+
# add to directives
|
13
|
+
#plugin_directives "#define EXAMPLE 10"
|
14
|
+
|
15
|
+
# add to external variables
|
16
|
+
# ok, we need to deal with
|
17
|
+
# what about variables
|
18
|
+
# need to loose the colon...
|
19
|
+
# external_variables "char status_message[40] = \"very cool\"", "char* msg[40]"
|
20
|
+
|
21
|
+
# add the following to the setup method
|
22
|
+
# add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
|
23
|
+
|
24
|
+
# one or more methods may be added and prototypes are generated automatically with rake make:upload
|
25
|
+
|
26
|
+
# call pulse(us) to pulse a servo
|
27
|
+
|
28
|
+
#####################
|
29
|
+
|
30
|
+
## How this works
|
31
|
+
|
32
|
+
## The cast:
|
33
|
+
## a normally open push button (circuit is closed when button is depressed)
|
34
|
+
## variables [input].
|
35
|
+
## [input]read: or current read -- what we see from the input pin HIGH (1) untouched or LOW (1) depressed
|
36
|
+
## [input]prev: or previous read – assigned to current reading at the end of the method
|
37
|
+
## [input]state: the stored state HIGH (1) or LOW (0)
|
38
|
+
## [input]time: the time when we last had a true
|
39
|
+
## millis: number of milliseconds since the Arduino began running the current program
|
40
|
+
|
41
|
+
## So….
|
42
|
+
|
43
|
+
## If HIGH and the [input]read was LOW (button was depressed since the last time we looped) AND If millis() - [input]time > 200
|
44
|
+
## Flip the state
|
45
|
+
## And assign [input]time millis()
|
46
|
+
## Else Set the pin to [input]state
|
47
|
+
## Assign [input]prev to [input]read
|
48
|
+
|
49
|
+
## abstract summary:
|
50
|
+
|
51
|
+
## So 99%+ of the time, we always see a HIGH (unless the button is pushed)
|
52
|
+
## If the button is pushed, we record this LOW to [input]prev, so the next time we enter the loop and the button is not being pushed we see true as long as millis() minus the [input]time of the last toggle is greater the 200 (adjust, which can be set with an adjust option)
|
53
|
+
|
54
|
+
|
55
|
+
######################
|
56
|
+
|
57
|
+
|
58
|
+
add_debounce_struct
|
59
|
+
|
60
|
+
# increase the debounce_setting, increase if the output flickers
|
61
|
+
# need docs..
|
62
|
+
# and testing
|
63
|
+
#
|
64
|
+
# remember these are being called from the loop (typically)
|
65
|
+
#
|
66
|
+
# NOTE: if two buttons are controlling one output, today, strange
|
67
|
+
# things will happen since each button tries to assert its own state
|
68
|
+
# suggestion: we can fix this with an array of structs for shared outputs
|
69
|
+
# ie: output_pin 5, :as => :yellow_led, :shared => :yes # default no
|
70
|
+
# this would put the state at the output which could be compared to
|
71
|
+
# the inputs_state and override and set it if different
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
int toggle(int output)
|
76
|
+
{
|
77
|
+
return toggle_output(output);
|
78
|
+
}
|
79
|
+
|
80
|
+
int toggle_output(int output)
|
81
|
+
{
|
82
|
+
if (dbce[output].state == HIGH)
|
83
|
+
dbce[output].state = LOW;
|
84
|
+
else
|
85
|
+
dbce[output].state = HIGH;
|
86
|
+
digitalWrite(output, dbce[output].state);
|
87
|
+
|
88
|
+
return dbce[output].state;
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
int read_input(int input)
|
93
|
+
{
|
94
|
+
int state = LOW;
|
95
|
+
dbce[input].read = digitalRead(input);
|
96
|
+
|
97
|
+
if (dbce[input].read == HIGH && dbce[input].prev == LOW && millis() - dbce[input].time > dbce[input].adjust)
|
98
|
+
{
|
99
|
+
dbce[input].time = millis();
|
100
|
+
state = HIGH;
|
101
|
+
}
|
102
|
+
else
|
103
|
+
state = LOW;
|
104
|
+
|
105
|
+
dbce[input].prev = dbce[input].read;
|
106
|
+
return state;
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
int toggle(int input, int output)
|
111
|
+
{
|
112
|
+
return read_and_toggle(input, output);
|
113
|
+
}
|
114
|
+
|
115
|
+
int read_and_toggle(int input, int output)
|
116
|
+
{
|
117
|
+
dbce[input].read = digitalRead(input);
|
118
|
+
// did we just release a button which was depressed the last time we checked and over 200 millseconds has passed since this statement was last true?
|
119
|
+
if (dbce[input].read == HIGH && dbce[input].prev == LOW && millis() - dbce[input].time > dbce[input].adjust) {
|
120
|
+
// ... flip the output
|
121
|
+
if (dbce[input].state == HIGH)
|
122
|
+
dbce[input].state = LOW;
|
123
|
+
else
|
124
|
+
dbce[input].state = HIGH;
|
125
|
+
|
126
|
+
/* save time of last press */
|
127
|
+
dbce[input].time = millis();
|
128
|
+
}
|
129
|
+
|
130
|
+
digitalWrite(output, dbce[input].state);
|
131
|
+
|
132
|
+
dbce[input].prev = dbce[input].read;
|
133
|
+
|
134
|
+
return dbce[input].state;
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class DebugOutputToLcd < ArduinoPlugin
|
2
|
+
|
3
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
4
|
+
# that may be added to the main setup method
|
5
|
+
# function prototypes not needed since we generate them automatically
|
6
|
+
|
7
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
8
|
+
|
9
|
+
# add to directives
|
10
|
+
#plugin_directives "#define ARY_SIZE 10"
|
11
|
+
|
12
|
+
# add to external variables
|
13
|
+
#external_variables "unsigned long start_loop_time = 0;", "unsigned long total_loop_time = 0;"
|
14
|
+
|
15
|
+
# add the following to the setup method
|
16
|
+
#add_to_setup "scan = &sm_ary[0];", "cur = &sm_ary[0];", "start = &sm_ary[0];", "end = &sm_ary[ARY_SIZE-1];"
|
17
|
+
|
18
|
+
# add an element to the array and return the average
|
19
|
+
|
20
|
+
# need a nice home for these
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
void send_servo_debug_to_lcd(int servo)
|
27
|
+
{
|
28
|
+
lcd_first_line();
|
29
|
+
Serial.print("pw ");
|
30
|
+
Serial.print( find_servo_pulse_width(servo));
|
31
|
+
Serial.print(" lp ");
|
32
|
+
Serial.print( find_servo_last_pulse(servo));
|
33
|
+
Serial.print("s");
|
34
|
+
Serial.print( find_servo_start_pulse(servo));
|
35
|
+
// Serial.print(" t");
|
36
|
+
// Serial.print( find_debounce_time(servo));
|
37
|
+
|
38
|
+
lcd_second_line();
|
39
|
+
Serial.print("d");
|
40
|
+
// Serial.print( millis() - find_debounce_time(servo));
|
41
|
+
Serial.print(" m");
|
42
|
+
Serial.print(millis());
|
43
|
+
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
void send_button_debug_to_lcd(int button)
|
48
|
+
{
|
49
|
+
|
50
|
+
lcd_first_line();
|
51
|
+
Serial.print("r");
|
52
|
+
Serial.print( find_debounce_read(button));
|
53
|
+
Serial.print("p");
|
54
|
+
Serial.print( find_debounce_prev(button));
|
55
|
+
Serial.print("s");
|
56
|
+
Serial.print( find_debounce_state(button));
|
57
|
+
Serial.print(" t");
|
58
|
+
Serial.print( find_debounce_time(button));
|
59
|
+
|
60
|
+
lcd_second_line();
|
61
|
+
Serial.print("d");
|
62
|
+
Serial.print( millis() - find_debounce_time(button));
|
63
|
+
Serial.print(" m");
|
64
|
+
Serial.print(millis());
|
65
|
+
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Hysteresis < ArduinoPlugin
|
2
|
+
|
3
|
+
# jdbarnhart
|
4
|
+
# 20080728
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# purpose
|
8
|
+
#
|
9
|
+
# add hysteresis to analog readings, typically sensors or potentiometers
|
10
|
+
#
|
11
|
+
# use
|
12
|
+
# two steps
|
13
|
+
#
|
14
|
+
# one
|
15
|
+
# declare :device => :sensor
|
16
|
+
# example:
|
17
|
+
# input_pin 1, :as => :sensor_one, :device => :sensor
|
18
|
+
#
|
19
|
+
# two
|
20
|
+
# instead of:
|
21
|
+
# my_lcd.print analogRead sensor_two
|
22
|
+
# use add_hyst
|
23
|
+
# my_lcd.print sensor_one.with_hyst 4
|
24
|
+
#
|
25
|
+
# # note, 4 is the amount of hysteresis
|
26
|
+
#
|
27
|
+
#
|
28
|
+
void with_hysteresis(int pin, int amt)
|
29
|
+
{
|
30
|
+
with_hyst(pin, amt);
|
31
|
+
}
|
32
|
+
|
33
|
+
int with_hyst(int pin, int amt)
|
34
|
+
{
|
35
|
+
int read;
|
36
|
+
unsigned int i;
|
37
|
+
read = analogRead(pin);
|
38
|
+
for (i = 0; i < (int) (sizeof(hyst) / sizeof(hyst[0])); i++) {
|
39
|
+
if (pin == hyst[i].pin) {
|
40
|
+
if (((read - hyst[i].state) > amt ) || ((hyst[i].state - read) > amt )) {
|
41
|
+
hyst[i].state = read;
|
42
|
+
return hyst[i].state;
|
43
|
+
}
|
44
|
+
else
|
45
|
+
return hyst[i].state;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class InputOutputState < ArduinoPlugin
|
2
|
+
|
3
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
4
|
+
# that may be added to the main setup method
|
5
|
+
# function prototypes not needed since we generate them automatically
|
6
|
+
|
7
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
8
|
+
|
9
|
+
# add to directives
|
10
|
+
#plugin_directives "#define ARY_SIZE 10"
|
11
|
+
|
12
|
+
# add to external variables
|
13
|
+
#external_variables "int *cur, *scan, *start, *end;", "int sm_ary[ARY_SIZE];"
|
14
|
+
|
15
|
+
# add the following to the setup method
|
16
|
+
#add_to_setup "scan = &sm_ary[0];", "cur = &sm_ary[0];", "start = &sm_ary[0];", "end = &sm_ary[ARY_SIZE-1];"
|
17
|
+
|
18
|
+
# return states of button and servo output stored in
|
19
|
+
# array structs dbcd (debounce) and serv (servo)
|
20
|
+
# need error catch ...
|
21
|
+
# how about auto generating documentation from plugins
|
22
|
+
# at least showing
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
int find_debounce_state(int input)
|
27
|
+
{
|
28
|
+
return dbce[input].state;
|
29
|
+
}
|
30
|
+
|
31
|
+
int find_debounce_read(int input)
|
32
|
+
{
|
33
|
+
return dbce[input].read;
|
34
|
+
}
|
35
|
+
|
36
|
+
int find_debounce_prev(int input)
|
37
|
+
{
|
38
|
+
return dbce[input].prev;
|
39
|
+
}
|
40
|
+
|
41
|
+
unsigned long find_debounce_time(int input)
|
42
|
+
{
|
43
|
+
return dbce[input].time;
|
44
|
+
}
|
45
|
+
|
46
|
+
int find_debounce_adjust(int input)
|
47
|
+
{
|
48
|
+
return dbce[input].adjust;
|
49
|
+
}
|
50
|
+
|
51
|
+
long unsigned find_servo_pulse_width(int input)
|
52
|
+
{
|
53
|
+
return serv[input].pulseWidth;
|
54
|
+
}
|
55
|
+
|
56
|
+
unsigned long find_servo_last_pulse(int input)
|
57
|
+
{
|
58
|
+
return serv[input].lastPulse;
|
59
|
+
}
|
60
|
+
|
61
|
+
unsigned long find_servo_start_pulse(int input)
|
62
|
+
{
|
63
|
+
return serv[input].startPulse;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
unsigned long find_servo_refresh_time(int input)
|
68
|
+
{
|
69
|
+
return serv[input].refreshTime;
|
70
|
+
}
|
71
|
+
|
72
|
+
int find_servo_min(int input)
|
73
|
+
{
|
74
|
+
return serv[input].min;
|
75
|
+
}
|
76
|
+
|
77
|
+
int find_servo_max(int input)
|
78
|
+
{
|
79
|
+
return serv[input].max;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
end
|