day/night determination
Posted: Thu Mar 03, 2011 6:36 pm
I used this code to make sure the board was seeing night when I thought it was night. dkirk mentioned there may be a variance with the cds between sources. I have some from Yeti, some from digikey, radio shack, and tayda. I didn't take the time to figure out if there are differences, or what the differences are.
Code: Select all
#rem
Coded By: tbass
Coded On: 2/26/2011
Reason: To determine my own ADC for day and night.
#endrem
#picaxe20x2
#terminal 9600
#no_table
disablebod
'###################################################################################################
'# Give the ports descriptive names
'###################################################################################################
Symbol inCDS = B.5 'CDS input to read light level
Symbol outCDS = C.5 'CDS Output to power CDS while checking light levels
Symbol outLED = B.2 'LED output
Input inCDS
Output outCDS
Symbol intADCVal = b4 'This is an integer value of the ADC reading
Symbol intCount = b6 'This is an integer to count with
Symbol dayThreshold = b7 'This is an integer to determine the day/night adc value
'###################################################################################################
'# Set up the ADC
'###################################################################################################
adcsetup = %010000000000 'Set up B.5 as an ADC Input
'########################
'
' Change dayThreshold higher if the board thinks it is night but it is not
' Change it lower if the board thinks it is daylight and it is not
'
'########################
dayThreshold = 130
getCDS:
High outCDS 'Put the output high to the divider circuit
readadc 10 , intADCVal 'Read the ADC value into intADCVal
Low outCDS 'Put the output low again
sertxd ("CDS ", #intADCVal,13,10)
sertxd ("Again",13,10)
'########################
'
' Change dayThreshold higher if the board thinks it is night but it is not
' Change it lower if the board thinks it is daylight and it is not
'
'########################
If intADCVal > dayThreshold then
for intCount = 1 to 10
toggle outLED 'blink 5 times
pause 300
next
Else
for intCount = 1 to 6
toggle outLED 'blink 3 times
pause 300
next
EndIf
Sleep 2
goto getCDS