rad 0.2.2 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/History.txt +34 -0
  2. data/Manifest.txt +113 -7
  3. data/{README.txt → README.rdoc} +17 -5
  4. data/Rakefile +3 -0
  5. data/bin/rad +106 -1
  6. data/lib/examples/add_hysteresis.rb +13 -0
  7. data/lib/examples/basic_blink.rb +10 -0
  8. data/lib/examples/blink_m_address_assignment.rb +104 -0
  9. data/lib/examples/blink_m_hello.rb +14 -0
  10. data/lib/examples/blink_m_multi.rb +61 -0
  11. data/lib/examples/blink_with_serial.rb +16 -0
  12. data/lib/examples/configure_pa_lcd_boot.rb +91 -0
  13. data/lib/examples/debounce_methods.rb +49 -0
  14. data/lib/examples/external_variable_fu.rb +26 -0
  15. data/lib/examples/external_variables.rb +32 -0
  16. data/lib/examples/first_sound.rb +23 -0
  17. data/lib/examples/frequency_generator.rb +30 -0
  18. data/lib/examples/hello_array.rb +48 -0
  19. data/lib/examples/hello_array2.rb +79 -0
  20. data/lib/examples/hello_array_eeprom.rb +59 -0
  21. data/lib/examples/hello_clock.rb +84 -0
  22. data/lib/examples/hello_eeprom.rb +51 -0
  23. data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
  24. data/lib/examples/hello_format_print.rb +94 -0
  25. data/lib/examples/hello_lcd_charset.rb +75 -0
  26. data/lib/examples/hello_pa_lcd.rb +59 -0
  27. data/lib/examples/hello_servos.rb +88 -0
  28. data/lib/examples/hello_spectra_sound.rb +38 -0
  29. data/lib/examples/hello_world.rb +11 -0
  30. data/lib/examples/hello_xbee.rb +12 -0
  31. data/lib/examples/hysteresis_duel.rb +39 -0
  32. data/lib/examples/i2c_with_clock_chip.rb +124 -0
  33. data/lib/examples/midi_beat_box.rb +86 -0
  34. data/lib/examples/midi_scales.rb +94 -0
  35. data/lib/examples/motor_knob.rb +30 -0
  36. data/lib/examples/servo_buttons.rb +23 -0
  37. data/lib/examples/servo_calibrate_continuous.rb +92 -0
  38. data/lib/examples/servo_throttle.rb +40 -0
  39. data/lib/examples/sparkfun_lcd.rb +48 -0
  40. data/lib/examples/spectra_soft_pot.rb +34 -0
  41. data/lib/examples/times_method.rb +8 -0
  42. data/lib/examples/toggle.rb +10 -0
  43. data/lib/examples/twitter.rb +57 -0
  44. data/lib/examples/two_wire.rb +14 -0
  45. data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
  46. data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
  47. data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
  48. data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
  49. data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
  50. data/lib/libraries/DS1307/DS1307.cpp +162 -0
  51. data/lib/libraries/DS1307/DS1307.h +66 -0
  52. data/lib/libraries/{SWSerLCDpa → DS1307}/keywords.txt +1 -1
  53. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
  54. data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
  55. data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
  56. data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
  57. data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
  58. data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
  59. data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
  60. data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
  61. data/lib/libraries/LoopTimer/keywords.txt +27 -0
  62. data/lib/libraries/OneWire/OneWire.cpp +194 -0
  63. data/lib/libraries/OneWire/OneWire.h +63 -0
  64. data/lib/libraries/OneWire/keywords.txt +35 -0
  65. data/lib/libraries/OneWire/readme.txt +13 -0
  66. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +93 -47
  67. data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +16 -9
  68. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
  69. data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
  70. data/lib/libraries/Servo/Servo.cpp +192 -0
  71. data/lib/libraries/Servo/Servo.h +61 -0
  72. data/lib/libraries/Stepper/Stepper.cpp +220 -0
  73. data/lib/libraries/Stepper/Stepper.h +86 -0
  74. data/lib/libraries/Stepper/keywords.txt +28 -0
  75. data/lib/libraries/Wire/Wire.cpp +262 -0
  76. data/lib/libraries/Wire/Wire.h +67 -0
  77. data/lib/libraries/Wire/keywords.txt +31 -0
  78. data/lib/libraries/Wire/twi.h +57 -0
  79. data/lib/libraries/Wire/utility/twi.c +449 -0
  80. data/lib/libraries/Wire/utility/twi.h +57 -0
  81. data/lib/plugins/bitwise_ops.rb +54 -0
  82. data/lib/plugins/blink.rb +25 -0
  83. data/lib/plugins/blink_m.rb +356 -0
  84. data/lib/plugins/debounce.rb +138 -0
  85. data/lib/plugins/debug_output_to_lcd.rb +71 -0
  86. data/lib/plugins/hysteresis.rb +52 -0
  87. data/lib/plugins/input_output_state.rb +84 -0
  88. data/lib/plugins/lcd_padding.rb +58 -0
  89. data/lib/plugins/mem_test.rb +37 -0
  90. data/lib/plugins/midi.rb +60 -0
  91. data/lib/plugins/parallax_ping.rb +50 -0
  92. data/lib/plugins/servo_pulse.rb +31 -0
  93. data/lib/plugins/servo_setup.rb +86 -0
  94. data/lib/plugins/smoother.rb +54 -0
  95. data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
  96. data/lib/plugins/spectra_symbol.rb +79 -0
  97. data/lib/plugins/twitter_connect.rb +145 -0
  98. data/lib/rad/README.rdoc +5 -0
  99. data/lib/rad/arduino_plugin.rb +246 -0
  100. data/lib/rad/arduino_sketch.rb +351 -257
  101. data/lib/rad/generators/makefile/makefile.erb +1 -1
  102. data/lib/rad/generators/makefile/makefile.rb +9 -10
  103. data/lib/rad/hardware_library.rb +813 -0
  104. data/lib/rad/init.rb +3 -1
  105. data/lib/rad/rad_processor.rb +128 -0
  106. data/lib/rad/rad_rewriter.rb +94 -0
  107. data/lib/rad/rad_type_checker.rb +26 -0
  108. data/lib/rad/sim/arduino_sketch.rb +57 -0
  109. data/lib/rad/sketch_compiler.rb +47 -0
  110. data/lib/rad/tasks/build_and_make.rake +146 -24
  111. data/lib/rad/variable_processing.rb +153 -0
  112. data/lib/rad/version.rb +1 -1
  113. data/spec/examples/hello_world.rb +11 -0
  114. data/spec/examples/serial_motor.rb +12 -0
  115. data/spec/models/sketch_compiler_spec.rb +96 -0
  116. data/spec/sim/hello_world_spec.rb +42 -0
  117. data/test/test_array_processing.rb +179 -0
  118. data/test/test_plugin_loading.rb +151 -0
  119. data/test/test_translation_post_processing.rb +185 -0
  120. data/test/test_variable_processing.rb +238 -0
  121. data/website/index.html +22 -7
  122. data/website/stylesheets/screen.css +32 -1
  123. metadata +130 -13
@@ -0,0 +1,59 @@
1
+ class HelloPaLcd < ArduinoSketch
2
+
3
+
4
+ # demonstrate 4 x 20 pa_lcd toggle between normal and Bignum mode
5
+ # with @toggle external variable thrown in for fun
6
+
7
+ # change your pins to suit your setup
8
+
9
+ @toggle = false
10
+
11
+ input_pin 6, :as => :button_one, :device => :button
12
+ input_pin 7, :as => :button_two, :device => :button
13
+ input_pin 8, :as => :button_three, :device => :button
14
+
15
+ output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
16
+
17
+ def setup
18
+ delay 3000
19
+ my_lcd.setxy 0,0
20
+ my_lcd.print "Press button"
21
+ my_lcd.setxy 0,1
22
+ my_lcd.print "One, two or three...."
23
+ end
24
+
25
+ def loop
26
+ say_hello if button_one.read_input
27
+ say_more if button_two.read_input
28
+ say_it_large if button_three.read_input
29
+ end
30
+
31
+ def say_hello
32
+ @toggle = true
33
+ my_lcd.clearscr "Any sufficiently advanced technology"
34
+ my_lcd.setxy 0,2
35
+ my_lcd.setxy 0,3, "toggle state: "
36
+ my_lcd.print @toggle
37
+ end
38
+
39
+ def say_more # passing print strings to home and setxy (also works on clearscr)
40
+ @toggle = false
41
+ my_lcd.clearscr "is indistinguishablefrom magic"
42
+ my_lcd.setxy 0,3, "toggle state: "
43
+ my_lcd.print @toggle
44
+ end
45
+
46
+
47
+ def say_it_large
48
+
49
+ my_lcd.intoBignum
50
+ my_lcd.clearscr # line 0, col 0
51
+ 1.upto(32) do |i|
52
+ my_lcd.setxy 0,1
53
+ my_lcd.print i * i
54
+ delay 200
55
+ end
56
+ my_lcd.outofBignum
57
+ end
58
+
59
+ end
@@ -0,0 +1,88 @@
1
+ class HelloServos < ArduinoSketch
2
+
3
+ output_pin 2, :as => :servo_1, :max => 2400, :min => 800
4
+ output_pin 3, :as => :servo_2, :max => 2400, :min => 800
5
+ output_pin 4, :as => :servo_3, :max => 2400, :min => 800
6
+
7
+
8
+ # time to go old school
9
+ def loop
10
+ song_sheet_two
11
+ end
12
+
13
+ def song_sheet_two
14
+ e
15
+ d
16
+ e
17
+ d
18
+ c
19
+ d
20
+ d
21
+ c
22
+ b
23
+ c
24
+ b
25
+ a
26
+ e
27
+ a
28
+ e
29
+ a
30
+ e
31
+ a
32
+ b
33
+ c
34
+ b
35
+ c
36
+ d
37
+ d
38
+ c
39
+ d
40
+ e
41
+ d
42
+ e
43
+ end
44
+
45
+ def a
46
+ pulse_servo servo_1, 1450
47
+ delay 100
48
+ home servo_1
49
+ delay 20
50
+ end
51
+
52
+ def b
53
+ pulse_servo servo_1, 1350
54
+ delay 100
55
+ home servo_1
56
+ delay 20
57
+ end
58
+
59
+ def c
60
+ pulse_servo servo_2, 1450
61
+ delay 100
62
+ home servo_2
63
+ delay 20
64
+ end
65
+
66
+ def d
67
+ pulse_servo servo_2, 1350
68
+ delay 100
69
+ home servo_2
70
+ delay 20
71
+ end
72
+
73
+ def e
74
+ pulse_servo servo_3, 1500
75
+ delay 100
76
+ home servo_3
77
+ delay 20
78
+ end
79
+
80
+
81
+ # center servos
82
+
83
+ def home(s)
84
+ pulse_servo s, 1400
85
+ f = s + 0
86
+ end
87
+
88
+ end
@@ -0,0 +1,38 @@
1
+ class HelloSpectraSound < 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
+ @reading = int
11
+ output_pin 14, :as => :my_lcd, :device => :pa_lcd, :rate => 9600, :clear_screen => :true
12
+ output_pin 11, :as => :sound, :device => :freq_out, :frequency => 100, :enable => :true
13
+ input_pin 3, :as => :sensor_one, :device => :spectra
14
+
15
+
16
+ def setup
17
+ delay 1000
18
+ my_lcd.setxy 0,0, "spectra symbol"
19
+ my_lcd.setxy 0,1, "soft pot sound"
20
+ delay 3000
21
+ my_lcd.clearscr
22
+ end
23
+
24
+ def loop
25
+ my_lcd.setxy 0,1
26
+ # since lcd's have issues clearing tens and hundreds digits when reading ones,
27
+ # we use pad_int_to_str, which is a hack to display these cleanly
28
+ # pad_int_to_str takes two arguments: an integer and the final string length
29
+ #
30
+ # my_lcd.print pad_int_to_str analogRead(sensor_one), 5
31
+ @reading = sensor_one.soft_lock
32
+ sound.set_frequency @reading * 10
33
+ my_lcd.print pad_int_to_str @reading, 3
34
+ delay 30
35
+ end
36
+
37
+
38
+ end
@@ -0,0 +1,11 @@
1
+ class HelloWorld < ArduinoSketch
2
+
3
+ output_pin 13, :as => :led
4
+
5
+ def loop
6
+ blink led, 100
7
+ end
8
+
9
+ end
10
+
11
+
@@ -0,0 +1,12 @@
1
+ class HelloXbee < ArduinoSketch
2
+
3
+ output_pin 13, :as => :led
4
+
5
+ serial_begin
6
+ def loop
7
+ led.blink 200
8
+ serial_print "...testing..."
9
+ delay 1000
10
+ end
11
+
12
+ end
@@ -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,124 @@
1
+ class I2cWithClockChip < ArduinoSketch
2
+
3
+ # ----------------------------------------------------------------------------------
4
+ # <b>Time and Temp (20 July 2008)</b>
5
+ # Example #1 - Brian Riley, Underhill Center, VT USA <brianbr@wulden.org>
6
+ #
7
+ # Connections
8
+ # I2C bus - DS1307 Real Time Clock chip
9
+ # Analog 0 (a.k.a Digital 14) - Wulfden K107 seria LCD Controller
10
+ # Peter Anderson chip
11
+ # Digital 8 - Dallas SemiConductor DS18B20 One-Wire temperature Sensor (12 bit)
12
+ #
13
+ # Comment
14
+ # - This is a straight forward, program with minimal error checking and brute force
15
+ # delay() calls waiting for temperature conversion readings
16
+ #
17
+ # - for the external data busses make sure you have 4.7K pullup resistors on the
18
+ # data line (OnewWire) and the SDA/SCL (I2C)
19
+
20
+ # ----------------------------------------------------------------------------------
21
+
22
+ @hi_byte = int
23
+ @lo_byte = int
24
+ @t_reading = int
25
+ @device_crc = int
26
+ @sign_bit = int
27
+ @tc_100 = int
28
+ # implicit in :device => Z:ds1307 is that this i i2c
29
+ # :enable => true issues the Wire.begin to ick over i2c
30
+ output_pin 19, :as => :rtc, :device => :i2c_ds1307, :enable => :true
31
+ # software serial tx drives LCD display, screen cleared at startup
32
+ # defines the softare protocol for controller as Peter Anderson
33
+ output_pin 14, :as => :myLCD, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
34
+ # defines this pin as being connected to a DalSemi 1-Wire device
35
+ # no specific device drivers yet, the specific device code is on you
36
+ output_pin 8, :as => :myTemp, :device => :onewire
37
+
38
+
39
+ def loop
40
+ until myTemp.reset do # reset bus, verify its clear and high
41
+ clear_bottom_line
42
+ myLCD.print " <1Wire Buss Error>"
43
+ delay 2000
44
+ end
45
+
46
+ myTemp.skip # "listen up - everybody!"
47
+ myTemp.write 0x44, 1 # temperature sensors, strta conversion
48
+
49
+ myLCD.setxy 6,0 # while they do that, lets print date/time
50
+ myLCD.print rtc.get(5, 1)
51
+ myLCD.print "/"
52
+ myLCD.print rtc.get(4, 0)
53
+ myLCD.print "/"
54
+ myLCD.print rtc.get(6, 0)
55
+ myLCD.setxy 6,1
56
+ printlz rtc.get(2, 0)
57
+ myLCD.print ":"
58
+ printlz rtc.get(1, 0)
59
+ myLCD.print ":"
60
+ printlz rtc.get(0, 0)
61
+
62
+ delay 800 # conversion takes about 750 msecs
63
+
64
+ until myTemp.reset do # reset bus, verify its clear and high
65
+ clear_bottom_line
66
+ myLCD.print " <1Wire Buss Error>"
67
+ delay 2000
68
+ end
69
+ myTemp.skip # listen up!
70
+ myTemp.write 0xBE, 1 # send me your data conversions
71
+
72
+ @lo_byte = myTemp.read # get irst byte
73
+ @hi_byte = myTemp.read # get second byte
74
+
75
+ # -------------------------------------------------------------
76
+ clear_bottom_line # this code is debug - not necessary
77
+ myLCD.setxy 4,3 # raw hex display of temp value
78
+ myLCD.print "raw = 0x"
79
+ print_hexbyte @hi_byte # prints 2 digit hex w/lead 0
80
+ print_hexbyte @lo_byte
81
+ # -------------------------------------------------------------
82
+
83
+ 7.times { @device_crc = myTemp.read } # get next 6 bytes, drop them on floor
84
+ # next byte the ninth byte is the CRC
85
+
86
+ # DS18B20 brings data temperature back as 12 bits
87
+ # in degrees centigrade with 4 bits fractional, that is
88
+ # each bit s 1/16 of a degreeC
89
+
90
+ @t_reading = build_int @hi_byte, @lo_byte
91
+ @sign_bit = bit_and @t_reading, 0x8000
92
+ @t_reading = twos_comp @t_reading if @sign_bit # negative
93
+
94
+ @tc_100 = (6 * @t_reading) + (@t_reading / 4) #multiply by (100 * 0.0625) or 6.25
95
+
96
+ myLCD.setxy 2,2
97
+ if @sign_bit
98
+ myLCD.print "-"
99
+ else
100
+ myLCD.print " "
101
+ end
102
+ myLCD.print(@tc_100 / 100) # separate off the whole
103
+ myLCD.print "."
104
+ printlz(@tc_100 % 100) # and fractional portions
105
+ myLCD.print " degrees C"
106
+
107
+ end
108
+
109
+ def printlz(w)
110
+ myLCD.print "0" if w < 10
111
+ myLCD.print w
112
+ end
113
+
114
+ def print_hexbyte(w)
115
+ myLCD.print "0" if w < 0x10
116
+ myLCD.print w, 0x10
117
+ end
118
+
119
+ def clear_bottom_line
120
+ myLCD.setxy 0,3
121
+ myLCD.print "?l"
122
+ end
123
+
124
+ end
@@ -0,0 +1,86 @@
1
+ class MidiBeatBox < ArduinoSketch
2
+
3
+ # midi synthesiser output on channel 2
4
+ # with speed controlled by spectra soft pot
5
+
6
+ @channel = 2
7
+ input_pin 1, :as => :sensor_one, :device => :spectra
8
+ output_pin 13, :as => :led
9
+
10
+ serial_begin :rate => 31250
11
+
12
+ def setup
13
+ delay 3000
14
+ end
15
+
16
+ def loop
17
+ 8.times {first}
18
+ 2.times do
19
+ second
20
+ third
21
+ end
22
+ 4.times {first}
23
+ 2.times {second}
24
+ end
25
+
26
+ def first
27
+ play 39, 52, 37
28
+ play 0, 0, 0
29
+ play 36, 52, 0
30
+ play 37, 52, 39
31
+
32
+ play 37, 0, 0
33
+ play 36, 0, 0
34
+ play 39, 50, 0
35
+ play 0, 0, 0
36
+
37
+ play 52, 36, 37
38
+ play 0, 0, 0
39
+ play 39, 0, 0
40
+ play 36, 37, 0
41
+
42
+ play 36, 37, 39
43
+ play 36, 38, 0
44
+ play 50, 0, 0
45
+ play 0, 0, 0
46
+ end
47
+
48
+ def second
49
+ play 39, 52, 37
50
+ play 36, 0, 0
51
+ play 0, 0, 0
52
+ play 37, 52, 39
53
+
54
+ play 38, 0, 0
55
+ play 36, 0, 0
56
+ play 39, 50, 0
57
+ play 0, 0, 0
58
+ end
59
+
60
+ def third
61
+ play 0, 36, 37
62
+ play 0, 0, 0
63
+ play 39, 36, 0
64
+ play 36, 37, 50
65
+
66
+ play 36, 37, 39
67
+ play 36, 37, 0
68
+ play 50, 0, 0
69
+ play 39, 0, 0
70
+ end
71
+
72
+
73
+ def play(one, two, three)
74
+ n = 1 + one + two + three # ack to coerce parameters to int
75
+ note_on(@channel, one, 127) unless one == 0
76
+ note_on(@channel, two, 127) unless two == 0
77
+ note_on(@channel, three, 127) unless three == 0
78
+ delay 310 - sensor_one.soft_lock # start slowly
79
+ note_off(@channel, one, 0) unless one == 0
80
+ note_off(@channel, two, 0) unless two == 0
81
+ note_off(@channel, three, 0) unless three == 0
82
+ end
83
+
84
+
85
+
86
+ end