My code is supposed to flash a light in sync with the temperature. It does and works pretty well (aside from the aforementioned problem flashing Zero times in part one)
The thing is simply a DS18B20 one wire temperature sensor using 12 bit accuracy and converting to degrees F, then breaking out the tens, units and hundreds to flash a common anode tricolor LED. 80 and above is red, 60-80 green, below 60 is blue.
It works but I want to also want to break up the colors further so that between75-80 flashes the tens in green and units in red - and I need a different way to do it than my current code because it uses too much program memory (and I still need to add a photocell so I can shut it down during daylight - that's easy but takes another couple of lines of code)
So, to make it clearer: 72 F should flash green 7 times pause, flash green 2 times -long pause and repeat. 75 F should flash green 7 times pause, flash red 5 times - long pause and repeat. (also to the same at 65, so 65 would flash blue 6, green 5)
My code so far:
The thing is simply a DS18B20 one wire temperature sensor using 12 bit accuracy and converting to degrees F, then breaking out the tens, units and hundreds to flash a common anode tricolor LED. 80 and above is red, 60-80 green, below 60 is blue.
It works but I want to also want to break up the colors further so that between75-80 flashes the tens in green and units in red - and I need a different way to do it than my current code because it uses too much program memory (and I still need to add a photocell so I can shut it down during daylight - that's easy but takes another couple of lines of code)
So, to make it clearer: 72 F should flash green 7 times pause, flash green 2 times -long pause and repeat. 75 F should flash green 7 times pause, flash red 5 times - long pause and repeat. (also to the same at 65, so 65 would flash blue 6, green 5)
My code so far:
Code:
'Main2 takes a 12 bit reading from the ds18 and converts celcius (times 16) to Fahrenheit
'then breaks out the digits into units,tens,hundreds for flashing led display
symbol C_raw = w0
symbol DegreesF = b4
symbol Celcius = b2
symbol tens = b10
symbol units = b11
symbol hundreds = b12
symbol red = 0
symbol blue = 1
symbol green = 2
high red
main2:
readtemp12 4,C_raw '12 bit reading from sensor
DegreesF = w0*9/80+32 'conversion to fahrenheit degrees (with divide by 16 included)
Celcius = w0/16 'just a place for degrees C for debugging purposes
units = DegreesF//10 'Decimal points 'breakout units
tens = DegreesF/10 'First digits 'tens
hundreds = DegreesF/100 'hundreds
'debug '(remarked)for troubleshooting purposes
'goto main2
pause 2000
if DegreesF>= 80 then redone
if DegreesF>= 60 then greenone
if DegreesF>= 0 then blueone
redone:
if degreesF>=100 then low red
pause 200
high red
pause 200
endif
pause 1000
for b5 = 1 to tens low red
pause 200
high red
pause 200
next
pause 1000
for b5 = 1 to units low red
pause 200
high red
pause 200
next
pause 1000
goto main2
greenone:
for b5 = 1 to tens low green
pause 200
high green
pause 200
next
pause 1000
for b5 = 1 to units low green
pause 200
high green
pause 200
next
pause 1000
goto main2
blueone:
for b5 = 1 to tens low blue
pause 200
high blue
pause 200
next
pause 1000
for b5 = 1 to units low blue
pause 200
high blue
pause 200
next
pause 1000
goto main2