Finished everything and it works pretty well. My only issue is where to put the LDR. Below is my code and some pictures of the circuit. I'm a novice at programming (and with PICAXE basic) so if you see a more efficient way to do it please comment! And this is for instantaneous fading whereas delayed fading might be more appropriate.
Code:
;LED Backlight PWM program V3 with instantaneous fading
;Written for Mazda3 CarPC by Tim Stocker
;
;Output 2 - LED Backlight
;Input 4 - LDR with 10kOhm Resistor
;Input 0 - Power-on V+ from monitor (9.45V = 65 w/100kOhm & 33.3kOhm voltage divider)
symbol LED = 2
symbol LDR = 4
symbol PWR = 0
setfreq m8 ;overclock to 8MHz
Startup:
readadc PWR,b3
if b3<50 then Standby
readadc LDR,b1
if b1>=160 then Sunny
if b1>80 and b1<160 then Dusk
if b1<=80 then Night
goto startup
Sunny:
readadc PWR,b3
if b3<50 then Standby
pwmout LED, 86, 275
readadc LDR,b1
if b1<=160 then DES_Sunny_to_Dusk
goto Sunny
DES_Sunny_to_Dusk:
readadc PWR,b3
if b3<50 then Standby
b2=254
for b2 = 254 to 100 step -1
pwmout LED, 88, b2
pause 5
next b2
goto Dusk
ASC_Dusk_to_Sunny:
readadc PWR,b3
if b3<50 then Standby
b2=100
for b2 = 100 to 254
pwmout LED, 88, b2
pause 5
next b2
goto Sunny
Dusk:
readadc PWR,b3
if b3<50 then Standby
pwmout LED, 90, 100
readadc LDR,b1
if b1>=180 then ASC_Dusk_to_Sunny
if b1<=80 then DES_Dusk_to_Night
goto Dusk
ASC_Night_to_Dusk:
readadc PWR,b3
if b3<50 then Standby
b2=20
for b2 = 20 to 100
pwmout LED, 92, b2
pause 5
next b2
goto Dusk
DES_Dusk_to_Night:
readadc PWR,b3
if b3<50 then Standby
b2=100
for b2 = 100 to 20 step -1
pwmout LED, 92, b2
pause 5
next b2
goto Night
Night:
readadc PWR,b3
if b3<50 then Standby
pwmout LED, 94, 20
readadc LDR,b1
if b1>=100 then ASC_Night_to_Dusk
goto Night
Standby:
pwmout LED, off
readadc PWR,b3
if b3<50 then Standby
goto Startup


Pretty simple program and circuit. The circuit is just the PICAXE controller, Darlington transistor array, a 12V regulator (soon to be a LDO 10V regulator since 12V is not necessary as the max voltage to the LED is 9.5V), and a 5V regulator for the PIC and LDR.
Bookmarks