madrona-rad 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/Manifest.txt +26 -0
- data/bin/rad +28 -36
- data/lib/examples/blink_m_hello.rb +14 -0
- data/lib/examples/debounce_methods.rb +49 -0
- data/lib/examples/external_variable_fu.rb +24 -0
- data/lib/examples/external_variables.rb +31 -0
- data/lib/examples/hello_eeprom.rb +54 -0
- data/lib/examples/i2c_with_clock_chip.rb +124 -0
- data/lib/examples/two_wire.rb +14 -0
- data/lib/libraries/DS1307/DS1307.cpp +161 -0
- data/lib/libraries/DS1307/DS1307.h +64 -0
- data/lib/libraries/DS1307/keywords.txt +18 -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/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/plugins/bitwise_ops.rb +54 -0
- data/lib/plugins/blink_m.rb +304 -6
- data/lib/plugins/debounce.rb +46 -24
- data/lib/plugins/i2c_eeprom.rb +70 -0
- data/lib/rad/arduino_plugin.rb +27 -4
- data/lib/rad/arduino_sketch.rb +354 -115
- data/lib/rad/generators/makefile/makefile.erb +2 -2
- data/lib/rad/generators/makefile/makefile.rb +5 -9
- data/lib/rad/init.rb +3 -1
- data/lib/rad/rad_processor.rb +11 -0
- data/lib/rad/rad_rewriter.rb +1 -1
- data/lib/rad/tasks/build_and_make.rake +25 -12
- data/lib/rad/variable_processing.rb +116 -0
- data/lib/test/test_array_processing.rb +78 -0
- data/lib/test/test_variable_processing.rb +188 -0
- metadata +29 -3
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.2.5 2008-07-21
|
2
|
+
* 1ish large post Bastille Day update:
|
3
|
+
- added i2c capability
|
4
|
+
- added actual Wire library until workaround for os_x file caching is found
|
5
|
+
- added DS1307 and OneWire libraries
|
6
|
+
- added cool instance variable style global variables
|
7
|
+
- added array and define methods
|
8
|
+
- added def setup method, which added to setup
|
9
|
+
- added numerous examples
|
10
|
+
|
1
11
|
== 0.2.4 2008-07-12
|
2
12
|
* 1ish large update:
|
3
13
|
- added incredibly primitive tests
|
data/Manifest.txt
CHANGED
@@ -5,19 +5,33 @@ README.rdoc
|
|
5
5
|
Rakefile
|
6
6
|
bin/rad
|
7
7
|
lib/examples/add_hysteresis.rb
|
8
|
+
lib/examples/blink_m_hello.rb
|
9
|
+
lib/examples/debounce_methods.rb
|
10
|
+
lib/examples/external_variables.rb
|
11
|
+
lib/examples/external_variable_fu.rb
|
8
12
|
lib/examples/first_sound.rb
|
9
13
|
lib/examples/frequency_generator.rb
|
14
|
+
lib/examples/hello_eeprom.rb
|
10
15
|
lib/examples/hello_servos.rb
|
11
16
|
lib/examples/hello_world.rb
|
17
|
+
lib/examples/i2c_with_clock_chip.rb
|
12
18
|
lib/examples/orig_servo_throttle.rb
|
13
19
|
lib/examples/servo_buttons.rb
|
14
20
|
lib/examples/servo_throttle.rb
|
15
21
|
lib/examples/sparkfun_lcd.rb
|
16
22
|
lib/examples/times_method.rb
|
17
23
|
lib/examples/toggle.rb
|
24
|
+
lib/examples/two_wire.rb
|
25
|
+
lib/libraries/DS1307/DS1307.cpp
|
26
|
+
lib/libraries/DS1307/DS1307.h
|
27
|
+
lib/libraries/DS1307/keywords.txt
|
18
28
|
lib/libraries/FrequencyTimer2/keywords.txt
|
19
29
|
lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp
|
20
30
|
lib/libraries/FrequencyTimer2/FrequencyTimer2.h
|
31
|
+
lib/libraries/OneWire/keywords.txt
|
32
|
+
lib/libraries/OneWire/OneWire.cpp
|
33
|
+
lib/libraries/OneWire/OneWire.h
|
34
|
+
lib/libraries/OneWire/readme.txt
|
21
35
|
lib/libraries/Servo/keywords.txt
|
22
36
|
lib/libraries/Servo/Servo.cpp
|
23
37
|
lib/libraries/Servo/Servo.h
|
@@ -25,9 +39,17 @@ lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp
|
|
25
39
|
lib/libraries/SWSerLCDpa/SWSerLCDpa.h
|
26
40
|
lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp
|
27
41
|
lib/libraries/SWSerLCDsf/SWSerLCDsf.h
|
42
|
+
lib/libraries/Wire/Wire.cpp
|
43
|
+
lib/libraries/Wire/keywords.txt
|
44
|
+
lib/libraries/Wire/Wire.h
|
45
|
+
lib/libraries/Wire/twi.h
|
46
|
+
lib/libraries/Wire/utilities/twi.c
|
47
|
+
lib/libraries/Wire/utilities/twi.h
|
48
|
+
lib/plugins/bitwise_ops.rb
|
28
49
|
lib/plugins/blink_m.rb
|
29
50
|
lib/plugins/debounce.rb
|
30
51
|
lib/plugins/debug_output_to_lcd.rb
|
52
|
+
lib/plugins/i2c_eeprom.rb
|
31
53
|
lib/plugins/input_output_state.rb
|
32
54
|
lib/plugins/mem_test.rb
|
33
55
|
lib/plugins/servo_pulse.rb
|
@@ -39,13 +61,17 @@ lib/rad/arduino_sketch.rb
|
|
39
61
|
lib/rad/arduino_plugin.rb
|
40
62
|
lib/rad/rad_processor.rb
|
41
63
|
lib/rad/rad_rewriter.rb
|
64
|
+
lib/rad/variable_processing.rb
|
42
65
|
lib/rad/init.rb
|
43
66
|
lib/rad/todo.txt
|
44
67
|
lib/rad/tasks/build_and_make.rake
|
68
|
+
lib/rad/developer.rake
|
45
69
|
lib/rad/tasks/rad.rb
|
46
70
|
lib/rad/version.rb
|
47
71
|
lib/rad/generators/makefile/makefile.erb
|
48
72
|
lib/rad/generators/makefile/makefile.rb
|
73
|
+
lib/test/test_array_processing.rb
|
74
|
+
lib/test/test_variable_processing.rb
|
49
75
|
scripts/txt2html
|
50
76
|
setup.rb
|
51
77
|
spec/models/spec_helper.rb
|
data/bin/rad
CHANGED
@@ -103,9 +103,16 @@ puts
|
|
103
103
|
FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
|
104
104
|
puts "Successfully created your libraries directory."
|
105
105
|
|
106
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/DS1307/.", "#{sketch_name}/vendor/libraries/DS1307"
|
107
|
+
puts "Installed DS1307 into #{sketch_name}/vendor/libraries"
|
108
|
+
puts
|
106
109
|
|
107
110
|
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/FrequencyTimer2/.", "#{sketch_name}/vendor/libraries/FrequencyTimer2"
|
108
|
-
puts "Installed
|
111
|
+
puts "Installed FrequencyTimer2 into #{sketch_name}/vendor/libraries"
|
112
|
+
puts
|
113
|
+
|
114
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/OneWire/.", "#{sketch_name}/vendor/libraries/OneWire"
|
115
|
+
puts "Installed OneWire into #{sketch_name}/vendor/libraries"
|
109
116
|
puts
|
110
117
|
|
111
118
|
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Servo/.", "#{sketch_name}/vendor/libraries/Servo"
|
@@ -120,6 +127,10 @@ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDsf/.", "#{ske
|
|
120
127
|
puts "Installed SWSerLCDsf into #{sketch_name}/vendor/libraries"
|
121
128
|
puts
|
122
129
|
|
130
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Wire/.", "#{sketch_name}/vendor/libraries/Wire"
|
131
|
+
puts "Installed Wire into #{sketch_name}/vendor/libraries"
|
132
|
+
puts
|
133
|
+
|
123
134
|
# Build examples -- used for basic testing
|
124
135
|
|
125
136
|
FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
|
@@ -129,6 +140,14 @@ FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/examples/.", "#{sketch_name}/ex
|
|
129
140
|
puts "Installed examples into #{sketch_name}/examples"
|
130
141
|
puts
|
131
142
|
|
143
|
+
# Build test -- used testing
|
144
|
+
|
145
|
+
FileUtils.mkdir_p "#{sketch_name}/test"
|
146
|
+
puts "Successfully created your test directory."
|
147
|
+
|
148
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/test/.", "#{sketch_name}/test"
|
149
|
+
puts "Installed tests into #{sketch_name}/test"
|
150
|
+
puts
|
132
151
|
|
133
152
|
# Build vendor/plugins:
|
134
153
|
|
@@ -151,42 +170,15 @@ File.open("#{sketch_name}/#{sketch_name}.rb", "w") do |file|
|
|
151
170
|
file << <<-EOS
|
152
171
|
class #{sketch_name.split("_").collect{|c| c.capitalize}.join("")} < ArduinoSketch
|
153
172
|
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
# result "long unsigned foo = 0" and "int bar;"
|
159
|
-
# note while this is ruby, many methods and some operators you take for granted are not implemented
|
160
|
-
# some examples: blocks, case statements, +=
|
161
|
-
# keep it simple and remember that the arduino uses a simple loop
|
162
|
-
# you can branch out with your other methods here or use
|
163
|
-
# add_to_setup to call a method once (todo: look at signatures)
|
164
|
-
# since all the methods are converted to C, assumptions are made regarding variable types
|
165
|
-
# for example if we need integers to call serial_print hack = input + output + 1
|
166
|
-
# pin examples
|
167
|
-
# input_pin 10, :as => :back_on_button, :latch => :off
|
168
|
-
# input_pin 12, :as => :back_off_button, :latch => :off
|
169
|
-
# output_pin 5, :as => :red_led
|
170
|
-
# input_pin 8, :as => :red_button, :latch => :off, :adjust => 250
|
171
|
-
# output_pin 4, :as => :top_servo, :min => 700, :max => 2200
|
172
|
-
|
173
|
-
# three line servo (don't forget do declare servo_amount')
|
174
|
-
# sensor_position = analogRead(sensor)
|
175
|
-
# servo_amount = (sensor_position*2 + 500)
|
176
|
-
# move_servo top_servo, servo_amount
|
177
|
-
# one line debounce:
|
178
|
-
# debounce_toggle(button, led)
|
179
|
-
# debounce a read (returns high)
|
180
|
-
# do_something if debounce_read(button, led)
|
181
|
-
|
182
|
-
|
173
|
+
# looking for hints? check out the examples directory
|
174
|
+
# example sketches can be uploaded to your arduino with
|
175
|
+
# rake make:upload sketch=examples/hello_world
|
176
|
+
# just replace hello_world with other examples
|
183
177
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
# blink led, 100
|
189
|
-
# end
|
178
|
+
def loop
|
179
|
+
# your code here
|
180
|
+
end
|
181
|
+
|
190
182
|
end
|
191
183
|
EOS
|
192
184
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class DebounceMethods < ArduinoSketch
|
2
|
+
|
3
|
+
output_pin 13, :as => :led
|
4
|
+
input_pin 6, :as => :button_one, :device => :button # can also :adjust => 300
|
5
|
+
input_pin 7, :as => :button_two, :device => :button
|
6
|
+
input_pin 8, :as => :button_three, :device => :button
|
7
|
+
input_pin 9, :as => :button_four, :device => :button
|
8
|
+
input_pin 10, :as => :button_five, :device => :button
|
9
|
+
|
10
|
+
# depressing and releasing button_one, button_two or button_four do the same thing
|
11
|
+
# with a slightly different syntax and number of blinks
|
12
|
+
# button_three simply toggles the led with the read_and_toggle method
|
13
|
+
# button_five does it with a twist
|
14
|
+
|
15
|
+
def loop
|
16
|
+
blink_twice if read_input button_one
|
17
|
+
blink_three_times if read_input button_two
|
18
|
+
button_three.read_and_toggle led #
|
19
|
+
blink_three_times_basic if read_input button_four
|
20
|
+
blink_with_a_twist if read_input button_five
|
21
|
+
end
|
22
|
+
|
23
|
+
def blink_twice
|
24
|
+
2.times do |i|
|
25
|
+
led.blink 200 + i
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def blink_three_times
|
30
|
+
3.times { led.blink 200 }
|
31
|
+
end
|
32
|
+
|
33
|
+
# no blink helper
|
34
|
+
def blink_three_times_basic
|
35
|
+
4.times do
|
36
|
+
led.digitalWrite HIGH
|
37
|
+
delay 200
|
38
|
+
led.digitalWrite LOW
|
39
|
+
delay 200
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def blink_with_a_twist
|
44
|
+
20.times do |i|
|
45
|
+
led.blink i * 10
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ExternalVariableFu < ArduinoSketch
|
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"
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def loop
|
21
|
+
delay @six
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ExternalVariables < ArduinoSketch
|
2
|
+
|
3
|
+
define "DS1307_CTRL 7"
|
4
|
+
define "DS1308_CTRL 7"
|
5
|
+
array "char buffer[32];"
|
6
|
+
array "char bufferz[32];"
|
7
|
+
|
8
|
+
|
9
|
+
@foo = 1
|
10
|
+
@bidda = "badda"
|
11
|
+
@boom = "1, int"
|
12
|
+
@rad = "1.00"
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
def loop
|
17
|
+
|
18
|
+
delay 1
|
19
|
+
@foo = 2
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup # special one time only method
|
24
|
+
delay 100
|
25
|
+
delay 100
|
26
|
+
@foo = 10
|
27
|
+
5.times { delay 200 }
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class HelloEeprom < ArduinoSketch
|
2
|
+
|
3
|
+
output_pin 19, :as => :rtc, :device => :i2c_ds1307, :enable => :true
|
4
|
+
output_pin 19, :as => :mem0, :device => :i2c_eeprom
|
5
|
+
|
6
|
+
output_pin 14, :as => :myLCD, :device => :pa_lcd, :rate => 19200
|
7
|
+
|
8
|
+
def loop
|
9
|
+
myLCD.home # set to 0,0
|
10
|
+
myLCD.print rtc.get(5, 1) # refresh registers (=1) get month
|
11
|
+
myLCD.print "/"
|
12
|
+
myLCD.print rtc.get(4, 0) # no need to refresh (=0) get day
|
13
|
+
myLCD.print "/"
|
14
|
+
myLCD.print rtc.get(6, 0) # get year
|
15
|
+
myLCD.setxy(1,1) # set in 1 byte line 1 (second line)
|
16
|
+
printlz 2 # print hours with lead zero
|
17
|
+
myLCD.print ":"
|
18
|
+
printlz 1 # print minutes with lead zero
|
19
|
+
myLCD.print ":"
|
20
|
+
printlz 0 # print seconds with lead zero
|
21
|
+
|
22
|
+
|
23
|
+
myLCD.setxy 10,0
|
24
|
+
myLCD.print "write test"
|
25
|
+
myLCD.setxy 0,2
|
26
|
+
32.upto(109) do # write address of byte to that b yte
|
27
|
+
|x| i2c_eeprom_write_byte 0x50, x, x
|
28
|
+
myLCD.print(".") if x%2
|
29
|
+
delay 10
|
30
|
+
end
|
31
|
+
|
32
|
+
delay 2000
|
33
|
+
|
34
|
+
myLCD.setxy 0,2 # clears bottom two lines
|
35
|
+
myLCD.print "?l"
|
36
|
+
myLCD.setxy 0,3
|
37
|
+
myLCD.print "?l"
|
38
|
+
|
39
|
+
myLCD.setxy 10,0
|
40
|
+
myLCD.print "read test "
|
41
|
+
myLCD.setxy 0,2
|
42
|
+
# read and print 39 addresses with printable numbers
|
43
|
+
75.upto(113) { |x| myLCD.print(i2c_eeprom_read_byte(0x50, x)) }
|
44
|
+
delay 10000
|
45
|
+
myLCD.clearscr
|
46
|
+
end
|
47
|
+
|
48
|
+
def printlz(w)
|
49
|
+
i = 0 + rtc.get(w,0) # the '0 +' is YARH (Yet Another RubyToc Hack)
|
50
|
+
myLCD.print "0" if i < 10
|
51
|
+
myLCD.print i
|
52
|
+
end
|
53
|
+
|
54
|
+
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
|