I've combined a couple of tutorials I found on Adafruit to have a TMP36 
sensor running with visual results shown through a RGB LED. If the temp 
exceeds a predefined temp then the light turns red, otherwise it stays 
green. After the loop runs 85 times the LED stops responding. I tried to 
incorporate PWM.cleanup() but that didn't help.

Any help would be appreciated.

import Adafruit_BBIO.ADC as ADC
import Adafruit_BBIO.PWM as PWM
import time

sensor_pin = 'P9_40'
red = "P8_13"
blue = "P8_19"
green = "P9_14"

PWM.start(red, 100)
PWM.start(blue, 100)
PWM.start(green, 100)
count = 0
ADC.setup()
PWM.cleanup()

while True:
    reading = ADC.read(sensor_pin)
    millivolts = reading * 1800  # 1.8V reference = 1800 mV
    temp_c = (millivolts - 500) / 10
    temp_f = (temp_c * 9/5) + 32
    PWM.start(green, 100)   # reset green light off
    PWM.start(red, 100)     # reset red light off
    PWM.start(blue,100)     # reset blue light off

    count = count + 1

    if temp_f < 82:
        print('Normal Temp -- (COUNT=%d) Celcius=%d; Fahrenheit=%d' % 
(count, temp_c, temp_f))
        PWM.start(green, 0)

    else:
        print('DANGER -- TOO HOT (COUNT=%d) Celcius=%d; Fahrenheit=%d' % 
(count, temp_c, temp_f))
        PWM.start(red, 0)

    time.sleep(1)

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to