class I2cWithClockChip

Public Instance Methods

clear_bottom_line() click to toggle source
# File lib/examples/i2c_with_clock_chip.rb, line 119
def clear_bottom_line
                  myLCD.setxy 0,3
                  myLCD.print "?l"
end
loop() click to toggle source
# 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
print_hexbyte(w) click to toggle source
printlz(w) click to toggle source
# File lib/examples/i2c_with_clock_chip.rb, line 109
def printlz(w)
                    myLCD.print "0" if w < 10
                    myLCD.print w
end