madrona-rad 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/History.txt +14 -0
  2. data/Manifest.txt +41 -18
  3. data/Rakefile +5 -0
  4. data/bin/rad +16 -6
  5. data/lib/examples/blink_m_address_assignment.rb +104 -0
  6. data/lib/examples/blink_m_multi.rb +61 -0
  7. data/lib/examples/configure_pa_lcd_boot.rb +91 -0
  8. data/lib/examples/external_variables.rb +5 -1
  9. data/lib/examples/hello_array.rb +48 -0
  10. data/lib/examples/hello_array2.rb +79 -0
  11. data/lib/examples/hello_array_eeprom.rb +61 -0
  12. data/lib/examples/hello_eeprom.rb +4 -7
  13. data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
  14. data/lib/examples/hello_lcd_charset.rb +75 -0
  15. data/lib/examples/hello_pa_lcd.rb +59 -0
  16. data/lib/examples/hysteresis_duel.rb +39 -0
  17. data/lib/examples/motor_knob.rb +30 -0
  18. data/lib/examples/orig_servo_throttle.rb +1 -1
  19. data/lib/examples/servo_calibrate_continuous.rb +92 -0
  20. data/lib/examples/servo_throttle.rb +1 -1
  21. data/lib/examples/sparkfun_lcd.rb +2 -2
  22. data/lib/examples/spectra_soft_pot.rb +34 -0
  23. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +60 -25
  24. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +8 -2
  25. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +46 -27
  26. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +5 -2
  27. data/lib/libraries/Stepper/Stepper.cpp +220 -0
  28. data/lib/libraries/Stepper/Stepper.h +86 -0
  29. data/lib/libraries/Stepper/keywords.txt +28 -0
  30. data/lib/libraries/Wire/utility/twi.c +449 -0
  31. data/lib/libraries/Wire/utility/twi.h +57 -0
  32. data/lib/plugins/blink_m.rb +79 -46
  33. data/lib/plugins/hysteresis.rb +52 -0
  34. data/lib/plugins/lcd_padding.rb +39 -0
  35. data/lib/plugins/spectra_symbol.rb +79 -0
  36. data/lib/rad/arduino_plugin.rb +21 -0
  37. data/lib/rad/arduino_sketch.rb +231 -53
  38. data/lib/rad/init.rb +2 -2
  39. data/lib/rad/rad_processor.rb +42 -1
  40. data/lib/rad/rad_type_checker.rb +26 -0
  41. data/lib/rad/sim/arduino_sketch.rb +57 -0
  42. data/lib/rad/tasks/build_and_make.rake +4 -4
  43. data/lib/rad/variable_processing.rb +49 -12
  44. data/lib/rad/version.rb +1 -1
  45. data/test/test_array_processing.rb +179 -0
  46. data/test/test_plugin_loading.rb +151 -0
  47. data/test/test_translation_post_processing.rb +185 -0
  48. data/{lib/test → test}/test_variable_processing.rb +63 -13
  49. data/website/index.html +8 -7
  50. metadata +66 -30
  51. data/lib/test/test_array_processing.rb +0 -78
@@ -0,0 +1,39 @@
1
+ class HysteresisDuel < ArduinoSketch
2
+
3
+ # purpose
4
+ # side by side demo of affect of hysteresis on two different sensor readings
5
+ #
6
+ #
7
+
8
+ # requires one pa_lcd
9
+ # two sensors or potentiometers
10
+
11
+
12
+
13
+ output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
14
+ input_pin 1, :as => :sensor_one, :device => :sensor
15
+ input_pin 2, :as => :sensor_two, :device => :sensor
16
+
17
+ def setup
18
+ delay 1000
19
+ my_lcd.setxy 0,0, "hysteresis duel"
20
+ delay 5000
21
+ my_lcd.clearscr
22
+ end
23
+
24
+ def loop
25
+ my_lcd.setxy 0,0, "direct"
26
+ my_lcd.setxy 0,1, "one: "
27
+ my_lcd.print analogRead sensor_one
28
+ my_lcd.print " two: "
29
+ my_lcd.print analogRead sensor_two
30
+ my_lcd.setxy 0,2, "with hysteresis"
31
+ my_lcd.setxy 0,3, "one: "
32
+ my_lcd.print sensor_one.with_hyst 4
33
+ my_lcd.print " two: "
34
+ my_lcd.print sensor_two.with_hyst 4
35
+ delay 230
36
+ end
37
+
38
+
39
+ end
@@ -0,0 +1,30 @@
1
+ class MotorKnob < ArduinoSketch
2
+
3
+ # ----------------------------------------------------------
4
+ # MotorKnob adapted from Tom Igoe's Arduino Sketch
5
+ #
6
+ # Brian Riley - Underhill Center, VT, USA July 2008
7
+ # <brianbr@wulfden.org>
8
+ #
9
+ # A stepper motor follows the turns of a potentiometer
10
+ # (or other sensor) on analog input 0.
11
+ #
12
+ # http://www.arduino.cc/en/Reference/Stepper
13
+ # ----------------------------------------------------------
14
+
15
+ fourwire_stepper 8, 9, 10, 11, :as => :mystepper, :speed => 31, :steps => 200
16
+ input_pin 0, :as => :sensor
17
+
18
+
19
+ @previous = "0, int"
20
+ @value = "0, int"
21
+
22
+ def loop
23
+
24
+ @value = analogRead(sensor)
25
+ mystepper.set_steps @value - @previous
26
+ @previous = @value
27
+
28
+ end
29
+
30
+ end
@@ -27,7 +27,7 @@ class OrigServoThrottle < ArduinoSketch
27
27
 
28
28
  def servo_status
29
29
 
30
- my_lcd.home # line 0, col 0
30
+ my_lcd.setxy 0,0 # line 0, col 0
31
31
  my_lcd.print "Read Send"
32
32
  my_lcd.setxy 0,1 # line 1, col 0
33
33
  my_lcd.print sensor_position # need method of blanking out previous reading
@@ -0,0 +1,92 @@
1
+ class ServoCalibrateContinuous < ArduinoSketch
2
+
3
+ # ----------------------------------------------------------------------
4
+ # Program to calibrate a 'continuous' or 'modified' hobby servo
5
+ #
6
+ # Basically uses teh servo 'spped' command to send a speed
7
+ # of zero (0) to the servo continuously. You then use a small
8
+ # screwdriver to adjust the potentiometer on the sero until there
9
+ # is no motion whatsoever.
10
+ #
11
+ # The program strats off by commanding max speed clockwise and then
12
+ # counter clockwise. First the LED blinks rapidly for 2 seconds as
13
+ # a warning that motion is coming. Then the LED is turned on solid
14
+ # Then 2 seconds max rev clockwise, then two seconds max rev counter-
15
+ # clockwise. Then the LED is turned off and this followed by twenty
16
+ # second of the servo commanded to zero (0) speed. During this time
17
+ # you may adjust the servo for no motion. If you stilll have more
18
+ # adjustmenst to make you will be warned by the flashing LED to
19
+ # back off while it moves back and forth. This full speed motion
20
+ # is to let you knwo you have it right,
21
+ #
22
+ # The 20 second timer uses the Arduino millis() counter which
23
+ # rolls over after a couple million milliseconds. I made no attempt
24
+ # to allow for ths. If your servo isn't calibrated after a couple
25
+ # million milliseconds and the prgram jams up then (a) hit the reset
26
+ # button, or (b) give up!
27
+ #
28
+ # Brian Riley - Underhill Center, VT, USA July 2008
29
+ # <brianbr@wulfden.org>
30
+ #
31
+ # ----------------------------------------------------------------------
32
+
33
+
34
+ @test_state = "2, int"
35
+ @cycle_time = "0, long"
36
+
37
+
38
+ # This sets up to do four units at once
39
+ # You can comment the extra lines out or leave them in, if there's nothing
40
+ # connected, no harm, no foul!
41
+ output_pin 12, :as => :servo4, :device => :servo, :minp => 400, :maxp => 2600
42
+ output_pin 11, :as => :servo3, :device => :servo, :minp => 400, :maxp => 2600
43
+ output_pin 10, :as => :servo2, :device => :servo, :minp => 400, :maxp => 2600
44
+ output_pin 9, :as => :servo1, :device => :servo, :minp => 400, :maxp => 2600
45
+
46
+ output_pin 13, :as => :led
47
+
48
+
49
+
50
+ def loop
51
+ if @test_state == 2
52
+
53
+ 40.times { blink led, 50 } # 40 x 50 ms is a 2 second blinking light
54
+ # ** Warning! ** "... danger Will Robinson!"
55
+ toggle led # turn it on keep it on -- keep hands away
56
+ servo1.speed -90
57
+ servo2.speed -90
58
+ servo3.speed -90
59
+ servo4.speed -90
60
+ delay_servo 2000 # two full seconds max clockwise
61
+ servo1.speed 90
62
+ servo2.speed 90
63
+ servo3.speed 90
64
+ servo4.speed 90
65
+ delay_servo 2000 # two full seconds max counter clockwise
66
+
67
+ @test_state = 1 # setup for zero speed test/adjust
68
+ @cycle_time = millis + 20000
69
+ servo1.speed 0
70
+ servo2.speed 0
71
+ servo3.speed 0
72
+ servo4.speed 0
73
+ toggle led # lights off, OK you have 20 seconds to adjust
74
+ end
75
+
76
+ if @cycle_time - millis <= 0
77
+ @test_state = 2
78
+ else
79
+ servo_refresh
80
+ end
81
+
82
+ end
83
+
84
+
85
+ def delay_servo(t)
86
+ t.times do
87
+ delay 1
88
+ servo_refresh
89
+ end
90
+ end
91
+
92
+ end
@@ -25,7 +25,7 @@ class ServoThrottle < ArduinoSketch
25
25
 
26
26
  def servo_status
27
27
 
28
- my_lcd.home # line 0, col 0
28
+ my_lcd.setxy 0,0 # line 0, col 0
29
29
  my_lcd.print "Read Send"
30
30
  my_lcd.setxy 0,1 # line 1, col 0
31
31
  my_lcd.print sensor_position # need method of blanking out previous reading
@@ -21,7 +21,7 @@ class SparkfunLcd < ArduinoSketch
21
21
  # need a bit
22
22
 
23
23
  def say_hello
24
- my_lcd.home # line 0, col 0
24
+ my_lcd.setxy 0,0 # line 0, col 0
25
25
  my_lcd.print "All your base "
26
26
  my_lcd.setxy 0,1 # line 1, col 0
27
27
  my_lcd.print "are belong to us"
@@ -29,7 +29,7 @@ class SparkfunLcd < ArduinoSketch
29
29
  end
30
30
 
31
31
  def say_ruby
32
- my_lcd.home # line 0, col 0
32
+ my_lcd.setxy 0,0 # line 0, col 0
33
33
  my_lcd.print " Ruby + Arduino "
34
34
  my_lcd.setxy 0,1 # line 1, col 0
35
35
  my_lcd.print " RAD 0.2.4+ "
@@ -0,0 +1,34 @@
1
+ class SpectraSoftPot < ArduinoSketch
2
+
3
+ # demonstrate capability to use soft pot as traditional pot
4
+ # the last pot reading remains "locked" to the last touch point
5
+ # similar same behavior as ipod
6
+ #
7
+ # this sketch assumes a pa_lcd operating at 19200 and one
8
+ # spectra symbol softpot connected to analog pin 3
9
+ #
10
+
11
+ output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
12
+ input_pin 3, :as => :sensor_one, :device => :spectra
13
+
14
+
15
+ def setup
16
+ delay 1000
17
+ my_lcd.setxy 0,0, "spectra symbol"
18
+ my_lcd.setxy 0,1, "soft pot"
19
+ delay 5000
20
+ my_lcd.clearscr
21
+ end
22
+
23
+ def loop
24
+ my_lcd.setxy 0,1
25
+ # since lcd's have issues clearing tens and hundreds digits when reading ones,
26
+ # we use pad_int_to_str, which is a hack to display these cleanly
27
+ # pad_int_to_str takes two arguments: an integer and the final string length
28
+ #
29
+ my_lcd.print pad_int_to_str sensor_one.soft_lock, 3
30
+ delay 100
31
+ end
32
+
33
+
34
+ end
@@ -62,11 +62,9 @@ void SWSerLCDpa::begin(long speed)
62
62
 
63
63
  digitalWrite(_transmitPin, HIGH);
64
64
  delayMicroseconds( _bitPeriod); // if we were low this establishes the end
65
- delay(20);
66
- clearscr();
65
+ delay(50);
67
66
  if (_geometry)
68
- setgeo(_geometry);
69
-
67
+ setgeo(_geometry);
70
68
  }
71
69
 
72
70
  void SWSerLCDpa::print(uint8_t b)
@@ -98,7 +96,7 @@ void SWSerLCDpa::print(const char *s)
98
96
  {
99
97
  while (*s) {
100
98
  print(*s++);
101
- delay(1);
99
+ delay(2);
102
100
  }
103
101
  }
104
102
 
@@ -151,21 +149,69 @@ void SWSerLCDpa::println(void)
151
149
  void SWSerLCDpa::clearscr(void)
152
150
  {
153
151
  print("?f");
154
- delay(100);
152
+ delay(30);
153
+ }
154
+
155
+ void SWSerLCDpa::clearscr(const char *s)
156
+ {
157
+ clearscr();
158
+ print(s);
159
+ }
160
+
161
+ void SWSerLCDpa::clearscr(int n)
162
+ {
163
+ clearscr();
164
+ print(n);
165
+ }
166
+
167
+ void SWSerLCDpa::clearline(int line)
168
+ {
169
+ setxy(0,line);
170
+ print("?l");
171
+ delay(20);
155
172
  }
156
173
 
157
- void SWSerLCDpa::home(void)
174
+ void SWSerLCDpa::clearline(int line, const char *s)
158
175
  {
159
- print("?a");
176
+ clearline(line);
177
+ print(s);
178
+ }
179
+
180
+ void SWSerLCDpa::clearline(int line, int n)
181
+ {
182
+ clearline(line);
183
+ print(n);
184
+ }
185
+
186
+
187
+ void SWSerLCDpa::setxy(int x, int y)
188
+ {
189
+ print("?y");
190
+ print(y);
191
+ print("?x");
192
+ if (x < 10)
193
+ print('0');
194
+ print(x);
160
195
  delay(10);
161
196
  }
162
197
 
198
+ void SWSerLCDpa::setxy(int x, int y, const char *s)
199
+ {
200
+ setxy(x,y);
201
+ print(s);
202
+ }
203
+
204
+ void SWSerLCDpa::setxy(int x, int y, int n)
205
+ {
206
+ setxy(x,y);
207
+ print(n);
208
+ }
163
209
 
164
210
  void SWSerLCDpa::setgeo(int geometry)
165
211
  {
166
- print("?G");
167
- print(geometry);
168
- delay(200);
212
+ print("?G");
213
+ print(geometry);
214
+ delay(200);
169
215
  }
170
216
 
171
217
  void SWSerLCDpa::setintensity(int intensity)
@@ -188,17 +234,6 @@ void SWSerLCDpa::outofBignum(void)
188
234
  }
189
235
 
190
236
 
191
- void SWSerLCDpa::setxy(int x, int y)
192
- {
193
- print("?y");
194
- print(y);
195
- print("?x");
196
- if (x < 10)
197
- print('0');
198
- print(x);
199
- delay(10);
200
- }
201
-
202
237
 
203
238
  void SWSerLCDpa::println(char c)
204
239
  {
@@ -259,9 +294,9 @@ void SWSerLCDpa::printNumber(unsigned long n, uint8_t base)
259
294
  n /= base;
260
295
  }
261
296
 
262
- for (; i > 0; i--)
297
+ for (; i > 0; i--) {
263
298
  print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10));
264
-
265
- delay(8);
299
+ delay(2);
300
+ }
266
301
 
267
302
  }
@@ -45,12 +45,18 @@ class SWSerLCDpa
45
45
  void print(long, int);
46
46
  void println(void);
47
47
  void clearscr(void);
48
- void home(void);
48
+ void clearline(int);
49
+ void setxy(int, int);
50
+ void clearscr(const char[]);
51
+ void clearline(int, const char[]);
52
+ void setxy(int, int, const char[]);
53
+ void clearscr(int);
54
+ void clearline(int, int);
55
+ void setxy(int, int, int);
49
56
  void setgeo(int);
50
57
  void setintensity(int);
51
58
  void intoBignum(void);
52
59
  void outofBignum(void);
53
- void setxy(int, int);
54
60
  void println(char);
55
61
  void println(const char[]);
56
62
  void println(uint8_t);
@@ -64,8 +64,7 @@ void SWSerLCDsf::begin(long speed)
64
64
 
65
65
  digitalWrite(_transmitPin, HIGH);
66
66
  delayMicroseconds( _bitPeriod); // if we were low this establishes the end
67
- delay(20);
68
- clearscr();
67
+ delay(50);
69
68
  if (_geometry)
70
69
  setgeo(_geometry);
71
70
  }
@@ -142,7 +141,7 @@ void SWSerLCDsf::print(long n, int base)
142
141
  printNumber(n, base);
143
142
  }
144
143
 
145
- // -------- PHA unique codes -------------------------
144
+ // -------- Spark Fun unique codes -------------------------
146
145
 
147
146
  void SWSerLCDsf::clearscr(void)
148
147
  {
@@ -151,13 +150,53 @@ void SWSerLCDsf::clearscr(void)
151
150
  delay(100);
152
151
  }
153
152
 
154
- void SWSerLCDsf::home(void)
153
+ void SWSerLCDsf::clearscr(const char *s)
155
154
  {
155
+ clearscr();
156
+ print(s);
157
+ }
158
+
159
+ void SWSerLCDsf::clearscr(int n)
160
+ {
161
+ clearscr();
162
+ print(n);
163
+ }
164
+
165
+ void SWSerLCDsf::setxy(byte x, byte y)
166
+ {
167
+ byte posvar;
168
+
169
+ switch (y) {
170
+ case 0:
171
+ posvar = 128 + x;
172
+ break;
173
+ case 1:
174
+ posvar = 192+ x;
175
+ break;
176
+ case 2:
177
+ posvar = ((_cols == 16) ? 144 : 148) + x;
178
+ break;
179
+ case 3:
180
+ posvar = ((_cols == 16) ? 208 : 212) + x;
181
+ break;
182
+ }
156
183
  print((uint8_t) 0xFE);
157
- print((uint8_t) 0x80);
158
- delay(10);
184
+ print((uint8_t) posvar);
185
+ }
186
+
187
+ void SWSerLCDsf::setxy(byte x, byte y, const char *s)
188
+ {
189
+ setxy(x,y);
190
+ print(s);
159
191
  }
160
192
 
193
+ void SWSerLCDsf::setxy(byte x, byte y, int n)
194
+ {
195
+ setxy(x,y);
196
+ print(n);
197
+ }
198
+
199
+
161
200
  void SWSerLCDsf::setcmd(byte code, byte cmd)
162
201
  {
163
202
  print((uint8_t) code);
@@ -205,27 +244,7 @@ void SWSerLCDsf::setintensity(int intensity)
205
244
  delay(100);
206
245
  }
207
246
 
208
- void SWSerLCDsf::setxy(byte x, byte y)
209
- {
210
- byte posvar;
211
-
212
- switch (y) {
213
- case 0:
214
- posvar = 128 + x;
215
- break;
216
- case 1:
217
- posvar = 192+ x;
218
- break;
219
- case 2:
220
- posvar = ((_cols == 16) ? 144 : 148) + x;
221
- break;
222
- case 3:
223
- posvar = ((_cols == 16) ? 208 : 212) + x;
224
- break;
225
- }
226
- print((uint8_t) 0xFE);
227
- print((uint8_t) posvar);
228
- }
247
+
229
248
 
230
249
 
231
250