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,94 @@
1
+ class MidiScales < ArduinoSketch
2
+
3
+ # purpose
4
+ # trigger midi output with buttons and
5
+ # spectra soft pots
6
+ #
7
+ #
8
+
9
+
10
+ @current_note = int
11
+ @last_note_one = 0
12
+ @last_note_two = 0
13
+ @last_note_three = 0
14
+ @note = int
15
+
16
+ input_pin 1, :as => :sensor_one, :device => :spectra
17
+ input_pin 2, :as => :sensor_two, :device => :spectra
18
+ input_pin 3, :as => :sensor_three, :device => :spectra
19
+ input_pin 7, :as => :button_one, :device => :button
20
+ input_pin 8, :as => :button_two, :device => :button
21
+ input_pin 9, :as => :button_three, :device => :button
22
+ output_pin 13, :as => :led
23
+
24
+ serial_begin :rate => 31250
25
+
26
+ def setup
27
+ delay 3000
28
+ end
29
+
30
+ def loop
31
+ change_tone if button_one.read_input
32
+ change_pressure if button_two.read_input
33
+ change_channels if button_three.read_input
34
+ read_sensor_one
35
+ read_sensor_two
36
+ read_sensor_three
37
+ end
38
+
39
+ def change_tone
40
+ 110.upto(127) do |note|
41
+ play 0, note, 127
42
+ end
43
+ end
44
+
45
+ def change_pressure
46
+ 110.upto(127) do |pressure|
47
+ play 0, 45, pressure
48
+ end
49
+ end
50
+
51
+ def change_channels
52
+ 0.upto(6) do |channel|
53
+ play channel, 50, 100
54
+ end
55
+ end
56
+
57
+ def read_sensor_one
58
+ @current_note = sensor_one.soft_lock
59
+ pre_play(@current_note, @last_note_one, 13)
60
+ @last_note_one = @current_note
61
+ end
62
+
63
+ def read_sensor_two
64
+ @current_note = sensor_two.soft_lock
65
+ pre_play(@current_note, @last_note_two, 14)
66
+ @last_note_two = @current_note
67
+ end
68
+
69
+ def read_sensor_three
70
+ @current_note = sensor_three.soft_lock
71
+ pre_play(@current_note, @last_note_three, 15)
72
+ @last_note_three = @current_note
73
+ end
74
+
75
+ def pre_play(current_note, last_note, channel) # warning, don't use last as a parameter...
76
+ n = 1 + channel
77
+ unless current_note == last_note
78
+ @note = ((current_note /16) + 40)
79
+ play_with_no_delay( channel, @note, 100 )
80
+ end
81
+ end
82
+
83
+ def play(chan, note, pressure)
84
+ note_on(chan, note, pressure)
85
+ delay 100 # adjust to need
86
+ note_off(chan, note, 0)
87
+ end
88
+
89
+ def play_with_no_delay(chan, note, pressure) # note is not turned off
90
+ note_on(chan, note, pressure)
91
+ end
92
+
93
+
94
+ 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
@@ -0,0 +1,23 @@
1
+ class ServoButtons < ArduinoSketch
2
+
3
+ # original syntax
4
+ input_pin 6, :as => :button_one, :latch => :off
5
+ # preferred syntax
6
+ input_pin 7, :as => :button_two, :device => :button
7
+ input_pin 8, :as => :button_three, :device => :button
8
+ output_pin 13, :as => :led
9
+ output_pin 2, :as => :my_servo, :device => :servo
10
+
11
+
12
+ def loop
13
+ check_buttons
14
+ servo_refresh
15
+ end
16
+
17
+ def check_buttons
18
+ read_and_toggle button_one, led
19
+ my_servo.position 180 if read_input button_two
20
+ my_servo.position 60 if read_input button_three
21
+ end
22
+
23
+ end
@@ -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
@@ -0,0 +1,40 @@
1
+ class ServoThrottle < ArduinoSketch
2
+
3
+ # updated 20080731
4
+ # replaced external variables with instance style variables
5
+
6
+ # potentiometer to control servo
7
+ # with a bit of hysteresis
8
+ # use analog pin for sensor
9
+ # need to format the output of sensor_position and sensor_amount
10
+
11
+ @sensor_position = 0
12
+ @servo_amount = 0
13
+
14
+ output_pin 5, :as => :my_lcd, :device => :sf_lcd
15
+ input_pin 1, :as => :sensor
16
+ output_pin 2, :as => :my_servo, :device => :servo
17
+
18
+
19
+ def loop
20
+ servo_refresh
21
+ #delay 9 # comment out if using servo status, since it will add enough delay
22
+ @sensor_position = analogRead(sensor)
23
+ @servo_amount = (add_hysteresis(@sensor_position, 10)*0.36)
24
+ my_servo.position @servo_amount
25
+ servo_status
26
+
27
+ end
28
+
29
+ def servo_status
30
+
31
+ my_lcd.setxy 0,0 # line 0, col 0
32
+ my_lcd.print "Read Send"
33
+ my_lcd.setxy 0,1 # line 1, col 0
34
+ my_lcd.print @sensor_position # need method of blanking out previous reading
35
+ my_lcd.setxy 6,1
36
+ my_lcd.print @servo_amount
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,48 @@
1
+ class SparkfunLcd < ArduinoSketch
2
+
3
+
4
+ input_pin 6, :as => :button_one, :latch => :off
5
+ input_pin 7, :as => :button_two, :latch => :off
6
+ input_pin 8, :as => :button_three, :latch => :off
7
+ output_pin 13, :as => :led
8
+
9
+ swser_LCDsf 5, :as => :my_lcd
10
+
11
+
12
+
13
+
14
+ #serial_begin # not necessary when using :device => :sf_lcd or :pa_lcd
15
+
16
+ def loop
17
+ check_buttons
18
+ end
19
+
20
+
21
+ # need a bit
22
+
23
+ def say_hello
24
+ my_lcd.setxy 0,0 # line 0, col 0
25
+ my_lcd.print "All your base "
26
+ my_lcd.setxy 0,1 # line 1, col 0
27
+ my_lcd.print "are belong to us"
28
+
29
+ end
30
+
31
+ def say_ruby
32
+ my_lcd.setxy 0,0 # line 0, col 0
33
+ my_lcd.print " Ruby + Arduino "
34
+ my_lcd.setxy 0,1 # line 1, col 0
35
+ my_lcd.print " RAD 0.2.4+ "
36
+ # un comment to change display startup
37
+ #myLCD.setcmd 0x7C, 10
38
+ end
39
+
40
+ def check_buttons
41
+ read_and_toggle button_one, led
42
+ say_hello if read_input button_two
43
+ say_ruby if read_input button_three
44
+
45
+
46
+ end
47
+
48
+ end
@@ -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
@@ -0,0 +1,8 @@
1
+ class TimesMethod < ArduinoSketch
2
+
3
+ def loop
4
+ 5.times { delay 200 }
5
+ end
6
+
7
+
8
+ end
@@ -0,0 +1,10 @@
1
+ class Toggle < ArduinoSketch
2
+
3
+ output_pin 13, :as => :led
4
+
5
+ def loop
6
+ led.toggle
7
+ delay 300
8
+ end
9
+
10
+ end
@@ -0,0 +1,57 @@
1
+ class Twitter < ArduinoSketch
2
+
3
+ #include <avr/io.h>
4
+ #include <string.h>
5
+
6
+
7
+
8
+ define "TWEETLEN 141"
9
+ define "HOSTNAME www.twitter.com"
10
+
11
+ define 'IPADDR "128.121.146.100"' # twitter.com
12
+ define "PORT 80" # // HTTP
13
+ define "HTTPPATH /atduskgreg/" # // the person we want to follow
14
+
15
+
16
+ define "TWEETLEN 141"
17
+ array "char linebuffer[256]" # // our large buffer for data
18
+ array "char tweet[TWEETLEN]" # // the tweet
19
+ @lines = 0
20
+
21
+
22
+ define "XPORT_RXPIN 2"
23
+ define "XPORT_TXPIN 3"
24
+ define "XPORT_RESETPIN 4"
25
+ define "XPORT_DTRPIN 5"
26
+ define "XPORT_CTSPIN 6"
27
+ define "XPORT_RTSPIN 7"
28
+
29
+
30
+ @errno = 0
31
+ @laststatus = 0
32
+ @currstatus = 0
33
+
34
+
35
+
36
+ # in setup
37
+ #xport = AF_XPort(XPORT_RX, XPORT_TX, XPORT_RESET, XPORT_DTR, XPORT_RTS, XPORT_CTS)
38
+
39
+
40
+ output_pin 10, :as => :shield, :device => :ethernet
41
+
42
+ serial_begin :rate => 57600
43
+
44
+ def loop
45
+
46
+ # local_connect()
47
+ # kind of a problem... fixed
48
+ get_tweet
49
+ fetchtweet
50
+ delay 30000
51
+
52
+
53
+ end
54
+
55
+
56
+
57
+ end