Class: I2cWithClockChip

Inherits:
ArduinoSketch show all
Defined in:
lib/examples/i2c_with_clock_chip.rb

Instance Attribute Summary

Attributes inherited from ArduinoSketch

#pins

Instance Method Summary collapse

Methods inherited from ArduinoSketch

#add, add_to_setup, #array, #assembler, #comment_box, #compose_setup, #define, #delay, #digitalWrite, #formatted_print, #initialize, #input_pin, #input_pins, output_pin, #output_pin, post_process_ruby_to_c_methods, pre_process, #serial_begin

Methods included from ExternalVariableProcessing

#c_type, #check_variable_type, #post_process_arrays, #post_process_vars, #pre_process_vars, #process_external_vars, #translate_variables

Constructor Details

This class inherits a constructor from ArduinoSketch

Instance Method Details

#clear_bottom_lineObject



119
120
121
122
# File 'lib/examples/i2c_with_clock_chip.rb', line 119

def clear_bottom_line
    myLCD.setxy 0,3
    myLCD.print "?l"
end

#loopObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/examples/i2c_with_clock_chip.rb', line 39

def loop
  until myTemp.reset do   # reset bus, verify its clear and high
    clear_bottom_line
    myLCD.print " <1Wire Buss Error>"
    delay 2000
  end
	
		myTemp.skip                 # "listen up - everybody!"
		myTemp.write 0x44, 1        # temperature sensors, strta conversion

		myLCD.setxy 6,0             # while they do that, lets print date/time
   myLCD.print rtc.get(5, 1)
   	myLCD.print "/"
   myLCD.print rtc.get(4, 0)
   	myLCD.print "/"
   myLCD.print rtc.get(6, 0)
   	myLCD.setxy 6,1
   	printlz rtc.get(2, 0)
   	myLCD.print ":"
   printlz rtc.get(1, 0)
   	myLCD.print ":"
   printlz rtc.get(0, 0)

		delay 800                   # conversion takes about 750 msecs

		until myTemp.reset do       # reset bus, verify its clear and high
		  clear_bottom_line
		  myLCD.print " <1Wire Buss Error>"
		  delay 2000
		end
 		myTemp.skip                 # listen up!
		myTemp.write 0xBE, 1        # send me your data conversions

    @lo_byte = myTemp.read      # get irst byte
    @hi_byte = myTemp.read      # get second byte
    
    # -------------------------------------------------------------
    clear_bottom_line       # this code is debug - not necessary
    myLCD.setxy 4,3         # raw hex display of temp value
    myLCD.print "raw = 0x"
    print_hexbyte @hi_byte  # prints 2 digit hex w/lead 0
    print_hexbyte @lo_byte
    # -------------------------------------------------------------

    7.times { @device_crc = myTemp.read } # get next 6 bytes, drop them on floor
                                          # next byte the ninth byte is the CRC
    
                            # DS18B20 brings data temperature back as 12 bits
                            # in degrees centigrade with 4 bits fractional, that is 
                            # each bit s 1/16 of a degreeC
                            
    @t_reading  =   build_int @hi_byte, @lo_byte
    @sign_bit   =   bit_and @t_reading, 0x8000
    @t_reading  =   twos_comp @t_reading   if @sign_bit  # negative

    @tc_100 = (6 * @t_reading) + (@t_reading / 4)   #multiply by (100 * 0.0625) or 6.25

    myLCD.setxy 2,2
    if @sign_bit
        myLCD.print "-"
    else
        myLCD.print " "
    end
    myLCD.print(@tc_100 / 100)             # separate off the whole 
    myLCD.print "."
    printlz(@tc_100 % 100)                  # and fractional portions
    myLCD.print " degrees C"

end


114
115
116
117
# File 'lib/examples/i2c_with_clock_chip.rb', line 114

def	print_hexbyte(w)
			myLCD.print "0" if w < 0x10
			myLCD.print w, 0x10
end

#printlz(w) ⇒ Object



109
110
111
112
# File 'lib/examples/i2c_with_clock_chip.rb', line 109

def	printlz(w)
			myLCD.print "0" if w < 10
			myLCD.print w
end