madrona-rad 0.2.7 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -15
- data/Manifest.txt +38 -5
- data/README.rdoc +19 -7
- data/Rakefile +4 -3
- data/bin/rad +214 -130
- data/lib/examples/basic_blink.rb +10 -0
- data/lib/examples/blink_with_serial.rb +16 -0
- data/lib/examples/external_variable_fu.rb +21 -19
- data/lib/examples/external_variables.rb +0 -3
- data/lib/examples/hello_array2.rb +34 -1
- data/lib/examples/hello_array_eeprom.rb +4 -6
- data/lib/examples/hello_clock.rb +84 -0
- data/lib/examples/hello_eeprom.rb +3 -3
- data/lib/examples/hello_eeprom_lcdpa.rb +2 -2
- data/lib/examples/hello_format_print.rb +94 -0
- data/lib/examples/hello_spectra_sound.rb +38 -0
- data/lib/examples/hello_world.rb +3 -3
- data/lib/examples/hello_xbee.rb +12 -0
- data/lib/examples/midi_beat_box.rb +86 -0
- data/lib/examples/midi_scales.rb +94 -0
- data/lib/examples/servo_throttle.rb +11 -8
- data/lib/examples/software_serial.rb +10 -0
- data/lib/examples/twitter.rb +57 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
- data/lib/libraries/{Servo → AFSoftSerial}/keywords.txt +18 -25
- 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 +10 -9
- data/lib/libraries/DS1307/DS1307.h +6 -4
- 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/SWSerLCDpa/SWSerLCDpa.cpp +42 -48
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +11 -12
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +38 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +9 -2
- data/lib/plugins/blink.rb +25 -0
- data/lib/plugins/blink_m.rb +3 -3
- data/lib/plugins/lcd_padding.rb +19 -0
- data/lib/plugins/midi.rb +60 -0
- data/lib/plugins/parallax_ping.rb +50 -0
- data/lib/plugins/servo_setup.rb +1 -1
- data/lib/plugins/twitter_connect.rb +145 -0
- data/lib/rad/README.rdoc +5 -0
- data/lib/rad/arduino_sketch.rb +91 -904
- data/lib/rad/darwin_installer.rb +23 -0
- data/lib/rad/generators/makefile/makefile.erb +1 -1
- data/lib/rad/generators/makefile/makefile.rb +3 -3
- data/lib/rad/hardware_library.rb +813 -0
- data/lib/rad/init.rb +4 -2
- data/lib/rad/linux_installer.rb +132 -0
- data/lib/rad/progressbar.rb +236 -0
- data/lib/rad/rad_processor.rb +56 -9
- data/lib/rad/rad_rewriter.rb +7 -2
- data/lib/rad/rad_type_checker.rb +1 -1
- data/lib/rad/sketch_compiler.rb +47 -0
- data/lib/rad/tasks/build_and_make.rake +41 -48
- data/lib/rad/version.rb +2 -2
- data/spec/examples/hello_world.rb +11 -0
- data/spec/examples/serial_motor.rb +12 -0
- data/spec/models/sketch_compiler_spec.rb +96 -0
- data/spec/sim/hello_world_spec.rb +0 -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 +1 -1
- data/test/test_plugin_loading.rb +1 -1
- data/test/test_translation_post_processing.rb +14 -70
- metadata +52 -39
- data/lib/examples/orig_servo_throttle.rb +0 -39
- data/lib/plugins/i2c_eeprom.rb +0 -70
@@ -1,24 +1,26 @@
|
|
1
1
|
class ExternalVariableFu < ArduinoSketch
|
2
2
|
|
3
|
-
@one = int
|
4
|
-
@two = long
|
5
|
-
@three = unsigned
|
6
|
-
@four = short
|
7
|
-
@five = byte
|
8
|
-
@six = 1
|
9
|
-
@seven = 1.2
|
10
|
-
@eight = "0x00"
|
11
|
-
@nine = "arduino"
|
12
|
-
@ten = true
|
13
|
-
@eleven = false
|
14
|
-
@twelve = "1, long"
|
15
|
-
@thirteen = "1, unsigned"
|
16
|
-
@fourteen = "1, byte"
|
3
|
+
@one = int
|
4
|
+
@two = long
|
5
|
+
@three = unsigned
|
6
|
+
@four = short
|
7
|
+
@five = byte
|
8
|
+
@six = 1
|
9
|
+
@seven = 1.2
|
10
|
+
@eight = "0x00"
|
11
|
+
@nine = "arduino"
|
12
|
+
@ten = true
|
13
|
+
@eleven = false
|
14
|
+
@twelve = "1, long"
|
15
|
+
@thirteen = "1, unsigned"
|
16
|
+
@fourteen = "1, byte"
|
17
|
+
@fifteen = HIGH
|
18
|
+
@sixteen = LOW
|
19
|
+
@seventeen = ON
|
20
|
+
@eighteen = OFF
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
delay @six
|
22
|
-
end
|
22
|
+
def loop
|
23
|
+
delay @six
|
24
|
+
end
|
23
25
|
|
24
26
|
end
|
@@ -24,7 +24,12 @@ class HelloArray2 < ArduinoSketch
|
|
24
24
|
array "int pizzas[] = {1,2,3,4}"
|
25
25
|
array "byte buffer[20] = {'A', 'B', 'Z', 'C', 'Y', 'D', 'W', 'E', '%', 'H', '*', '!', ')', '=', 'P', '-', '+', 'R', 'I', 'K'}"
|
26
26
|
|
27
|
-
|
27
|
+
## multidimensional arrays
|
28
|
+
array 'int @my_numbers[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}'
|
29
|
+
array 'char* @pizzas[2][4] = {{"margherita","funghi","napoletana","prosciutto cotto"},{"veggie","pepperoni","cheese","kitchen sink"}}'
|
30
|
+
|
31
|
+
|
32
|
+
output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
|
28
33
|
|
29
34
|
|
30
35
|
def setup
|
@@ -56,6 +61,8 @@ class HelloArray2 < ArduinoSketch
|
|
56
61
|
|
57
62
|
delay 3000
|
58
63
|
|
64
|
+
|
65
|
+
|
59
66
|
my_lcd.clearline 1, @names[2]
|
60
67
|
my_lcd.print " [ "
|
61
68
|
my_lcd.print pizzas[1]
|
@@ -63,6 +70,32 @@ class HelloArray2 < ArduinoSketch
|
|
63
70
|
|
64
71
|
delay 2000
|
65
72
|
|
73
|
+
my_lcd.clearscr "Multidimensional ?n"
|
74
|
+
|
75
|
+
0.upto(2) do |f|
|
76
|
+
0.upto(3) do |s|
|
77
|
+
my_lcd.print @my_numbers[f][s]
|
78
|
+
my_lcd.print ", "
|
79
|
+
delay 500
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
delay 1000
|
84
|
+
|
85
|
+
my_lcd.clearscr
|
86
|
+
|
87
|
+
0.upto(1) do |f|
|
88
|
+
0.upto(3) do |s|
|
89
|
+
my_lcd.print @pizzas[f][s]
|
90
|
+
my_lcd.print ", "
|
91
|
+
delay 500
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
delay 2000
|
98
|
+
|
66
99
|
my_lcd.clearscr "Array Load?n"
|
67
100
|
1.upto(20) do |x|
|
68
101
|
# buffer[x] = 64 + x # we cannot set array elements yet except to initialize in declaration
|
@@ -15,14 +15,12 @@ class HelloArrayEeprom < ArduinoSketch
|
|
15
15
|
# is at odds with original style array naming
|
16
16
|
|
17
17
|
define "THROWAWAY 0"
|
18
|
-
define "EEPROM_ADDR 0x50"
|
19
|
-
|
20
18
|
|
21
19
|
# when we just need to declare an array, or need more control, such as specific type requirements
|
22
|
-
array "byte page_data[20] = {'
|
20
|
+
array "byte page_data[20] = {'R', 'A', 'D', ' ', 'i', 's', ' ', 'B', 'A', 'D', '*', '!', ')', '=', 'P', '-', '+', 'R', 'I', 'K'}"
|
23
21
|
array "byte in_buffer[20]"
|
24
22
|
|
25
|
-
output_pin 19, :as => :mem0, :device => :i2c_eeprom, :
|
23
|
+
output_pin 19, :as => :mem0, :device => :i2c_eeprom, :address => 1 # w/o :address defaults to :address => 0 which is 0x50
|
26
24
|
output_pin 14, :as => :my_lcd, :device => :pa_lcd, :rate => 19200
|
27
25
|
|
28
26
|
|
@@ -37,13 +35,13 @@ class HelloArrayEeprom < ArduinoSketch
|
|
37
35
|
|
38
36
|
my_lcd.clearscr " I2C EEPROM Demo?n block write"
|
39
37
|
|
40
|
-
|
38
|
+
mem0.write_page 0x0100, page_data, 20
|
41
39
|
|
42
40
|
delay 1000
|
43
41
|
|
44
42
|
my_lcd.clearline 1, " block readback"
|
45
43
|
|
46
|
-
|
44
|
+
mem0.read_buffer 0x0100, in_buffer, 20
|
47
45
|
|
48
46
|
my_lcd.setxy 0, 2
|
49
47
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class HelloClock < 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
|
+
#
|
12
|
+
# Comment
|
13
|
+
# - This is a straight forward program to read the Real Time Clock and Display
|
14
|
+
# delay() calls waiting for temperature conversion readings
|
15
|
+
#
|
16
|
+
# - for the external data busses make sure you have 4.7K pullup resistors on the
|
17
|
+
# the SDA/SCL (I2C)
|
18
|
+
#
|
19
|
+
# ----------------------------------------------------------------------------------
|
20
|
+
|
21
|
+
@flag = int
|
22
|
+
|
23
|
+
array "byte clock[8]"
|
24
|
+
|
25
|
+
@days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
|
26
|
+
@months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
|
27
|
+
|
28
|
+
# implicit in :device => :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
|
+
loop_timer :as => :mainloop
|
35
|
+
|
36
|
+
|
37
|
+
def setup
|
38
|
+
myLCD.clearscr " --<Date/Time>--"
|
39
|
+
myLCD.setxy 1,3, "looptime = "
|
40
|
+
rtc.get clock, 1
|
41
|
+
print_main
|
42
|
+
@flag = 1
|
43
|
+
end
|
44
|
+
|
45
|
+
def loop
|
46
|
+
mainloop.track
|
47
|
+
myLCD.setxy 12,3, mainloop.get_total
|
48
|
+
rtc.get clock, 1
|
49
|
+
if clock[0] == 0
|
50
|
+
if @flag == 0
|
51
|
+
print_main
|
52
|
+
@flag = 1
|
53
|
+
end
|
54
|
+
else
|
55
|
+
@flag = 0
|
56
|
+
end
|
57
|
+
myLCD.setxy 6,2
|
58
|
+
printlz clock[2]
|
59
|
+
myLCD.print ":"
|
60
|
+
printlz clock[1]
|
61
|
+
myLCD.print ":"
|
62
|
+
printlz clock[0]
|
63
|
+
|
64
|
+
delay 50
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def printlz(w)
|
69
|
+
myLCD.print "0" if w < 10
|
70
|
+
myLCD.print w
|
71
|
+
end
|
72
|
+
|
73
|
+
def print_main
|
74
|
+
myLCD.setxy 1,1, @days[clock[3]-1]
|
75
|
+
myLCD.print ", "
|
76
|
+
myLCD.print @months[clock[5]-1]
|
77
|
+
myLCD.print " "
|
78
|
+
printlz clock[4]
|
79
|
+
myLCD.print ", "
|
80
|
+
printlz clock[6] + 2000
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -12,7 +12,7 @@ class HelloEeprom < ArduinoSketch
|
|
12
12
|
myLCD.print rtc.get(4, 0) # no need to refresh (=0) get day
|
13
13
|
myLCD.print "/"
|
14
14
|
myLCD.print rtc.get(6, 0) # get year
|
15
|
-
myLCD.setxy(
|
15
|
+
myLCD.setxy(0,1) # set in 1 byte line 1 (second line)
|
16
16
|
printlz 2 # print hours with lead zero
|
17
17
|
myLCD.print ":"
|
18
18
|
printlz 1 # print minutes with lead zero
|
@@ -24,7 +24,7 @@ class HelloEeprom < ArduinoSketch
|
|
24
24
|
myLCD.print "write test"
|
25
25
|
myLCD.setxy 0,2
|
26
26
|
32.upto(109) do # write address of byte to that b yte
|
27
|
-
|x|
|
27
|
+
|x| mem0.write_byte x, x
|
28
28
|
myLCD.print(".") if x%2
|
29
29
|
delay 10
|
30
30
|
end
|
@@ -37,7 +37,7 @@ class HelloEeprom < ArduinoSketch
|
|
37
37
|
myLCD.setxy 10,0, "read test "
|
38
38
|
myLCD.setxy 0,2
|
39
39
|
# read and print 39 addresses with printable numbers
|
40
|
-
75.upto(113) { |x| myLCD.print(
|
40
|
+
75.upto(113) { |x| myLCD.print(mem0.read_byte(x)) }
|
41
41
|
delay 10000
|
42
42
|
myLCD.clearscr
|
43
43
|
end
|
@@ -47,7 +47,7 @@ class HelloEepromLcdpa < ArduinoSketch
|
|
47
47
|
|
48
48
|
myLCD.setxy 0, 2
|
49
49
|
32.upto(109) do # write address of byte to that b yte
|
50
|
-
|x|
|
50
|
+
|x| mem0.write_byte x, x+7
|
51
51
|
myLCD.print(".") if x%2
|
52
52
|
delay 10 # EEPROM write _requires_ 3-10 ms pause
|
53
53
|
end
|
@@ -57,7 +57,7 @@ class HelloEepromLcdpa < ArduinoSketch
|
|
57
57
|
|
58
58
|
myLCD.setxy 0, 2
|
59
59
|
# read and print 39 addresses with printable numbers
|
60
|
-
|
60
|
+
70.upto(105) { |x| myLCD.print(mem0.read_byte(x)) }
|
61
61
|
|
62
62
|
delay 2000
|
63
63
|
clear_off_test
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class HelloFormatPrint < ArduinoSketch
|
2
|
+
|
3
|
+
# ----------------------------------------------------------------------
|
4
|
+
# Demonstrattion of Crude Adaptaion of C Function sprintf()
|
5
|
+
# to do formatted printing. For now there are some absolutes:
|
6
|
+
# The write_line method atkes as arguemnst the formatting string
|
7
|
+
# and the appropriate arguments. It format them to an internal
|
8
|
+
# buffer sepcified and created when you invoke formatted printing
|
9
|
+
# formatted_print :as => :line_buf, :buffer_size => 80
|
10
|
+
# now, to actual do it you use write_line
|
11
|
+
# write_line "Pies $%02d.%02d", pie_cents/100, pie_cents%100
|
12
|
+
# then print the string pointed at by string_line
|
13
|
+
# my_lcd.setxy 3, 2, line_buf
|
14
|
+
#
|
15
|
+
# Brian Riley - Underhill Center, VT, USA Aug 2008
|
16
|
+
# <brianbr@wulfden.org>
|
17
|
+
#
|
18
|
+
# ----------------------------------------------------------------------
|
19
|
+
|
20
|
+
# demonstrate 4 x 20 pa_lcd toggle between normal and Bignum mode
|
21
|
+
# with @toggle external variable thrown in for fun
|
22
|
+
|
23
|
+
# change your pins to suit your setup
|
24
|
+
|
25
|
+
@toggle = "0, int"
|
26
|
+
@pie_cents = "403, int"
|
27
|
+
@pie_price = "7.08"
|
28
|
+
|
29
|
+
|
30
|
+
input_pin 8, :as => :button_one, :device => :button
|
31
|
+
input_pin 9, :as => :button_two, :device => :button
|
32
|
+
input_pin 10, :as => :button_three, :device => :button
|
33
|
+
|
34
|
+
formatted_print :as => :string_line, :buffer_size => 65 # generally this statement should precede any serial_begin or
|
35
|
+
# LCD display directive
|
36
|
+
|
37
|
+
output_pin 14, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
|
38
|
+
|
39
|
+
|
40
|
+
def setup
|
41
|
+
my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
|
42
|
+
end
|
43
|
+
|
44
|
+
def loop
|
45
|
+
if millis % 500 == 0
|
46
|
+
write_line "millis()= %ld", millis
|
47
|
+
my_lcd.setxy 1, 2, string_line
|
48
|
+
end
|
49
|
+
say_hello if button_one.read_input
|
50
|
+
say_more if button_two.read_input
|
51
|
+
say_it_large if button_three.read_input
|
52
|
+
end
|
53
|
+
|
54
|
+
def say_hello
|
55
|
+
@toggle = true
|
56
|
+
my_lcd.clearscr "This sketch has?nbeen running for?n "
|
57
|
+
write_line "%ld mins and %d secs?n", millis/60000, (millis/1000)%60
|
58
|
+
my_lcd.print string_line
|
59
|
+
delay 3000
|
60
|
+
my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
|
61
|
+
end
|
62
|
+
|
63
|
+
def say_more # passing print strings to home and setxy (also works on clearscr)
|
64
|
+
@toggle = false
|
65
|
+
my_lcd.clearscr "Food Store Prices"
|
66
|
+
write_line "Pies $%2d.%02d", @pie_cents/100, @pie_cents%100
|
67
|
+
# write_line "Pies $%6.2f", @pie_price # float doessn't seem to work .....
|
68
|
+
my_lcd.setxy 2, 1, string_line
|
69
|
+
# write_line "toggle state is [%s]", @toggle ? "ON" : "OFF" # RubyToC screws this construct up and RAD mistajekl put 1 ad 0
|
70
|
+
# in place of "ON" and "OFF"
|
71
|
+
write_line "toggle state is [%d]", @toggle
|
72
|
+
my_lcd.setxy 2, 3, string_line
|
73
|
+
delay 3000
|
74
|
+
my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def say_it_large
|
79
|
+
|
80
|
+
my_lcd.intoBignum
|
81
|
+
my_lcd.clearscr # line 0, col 0
|
82
|
+
1.upto(32) do |i|
|
83
|
+
my_lcd.setxy 0,1
|
84
|
+
my_lcd.print i * i
|
85
|
+
delay 200
|
86
|
+
end
|
87
|
+
my_lcd.outofBignum
|
88
|
+
delay 3000
|
89
|
+
my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
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
|