Hey guys,
I've been having fun learning how to program these things.
Not wanting to work while at work I was going over the code. I came up with this...
Code:
symbol LED=2 'Output 2 - LED Backlight
symbol LDR=4 'Input 4 - LDR with 10Kohm resistor
symbol PWR=1 'Power-on V+ from monitor (9.45V = 65 w/100kOhm & 33.3kOhm voltage divider)
setfreq m8 'overclock to 8mhz
start:
readadc PWR,b10 'read power switch into b10
if b10<50 then standby
readadc LDR,b0 'read light sensor into b0
if b0>=160 then sun
if b0>80 and b0<160 then dusk
if b0<=80 then night
goto start
sun:
w1=800 'set pwm level into w1
goto pwmset 'NOTE - use even OR odd numbers for w1
dusk: 'or change lines 32 and 33 to + and - 1 instead of 2
w1=400
goto pwmset
night:
w1=160
goto pwmset
standby:
w1=2
goto pwmset
pwmset:
if w1=w2 then goto start 'if at same brightness goto start
if w2<=0 then:w2=w1:endif 'set starting brightness
do
pwmout LED,199,w2 'light the led
if w1<w2 then:let w2=w2-2:endif 'decrease brightness
if w1>w2 then:let w2=w2+2:endif 'increase brightness
loop while w1!=w2 'loop untill brightness = desired level
if w2=2 then:pwmout LED,off:endif 'when brightness at 2 turn off
goto start
I think it accomplishes the same things. This is my first attempt at programming anything so if you see a glaring error please let me know.
The numbers used for PWMOUT have not been tested in the real world. I just used the wizard to give me 100%, 50% and 20%. I bet they will have to be adjusted when I hook things up.
Thanks for inspiring me to do this.
davidk
Bookmarks