I am trying to create a circuit that is able to adjust the brightness of the LED accordingly to different light level. I want the light brightness vary with the surrounding brightness. If the surrounding brightness is low, the light will produce more brightness and vice versa.
For example:
100% brightness: dark surrounding
70% brightness: dim surrounding
0%(off) brightness: lighted surrounding
So far i am only able to make the LED turn on/off according to light/dark surrounding. I have also tried to use PWM command but my LED will not vary the brightness but dimming it till it turned off and repeat.
BTW, i am using pbasic programming.
Below is the codes i did. I am unable to post the image of my schematic cause i dont know how.
For example:
100% brightness: dark surrounding
70% brightness: dim surrounding
0%(off) brightness: lighted surrounding
So far i am only able to make the LED turn on/off according to light/dark surrounding. I have also tried to use PWM command but my LED will not vary the brightness but dimming it till it turned off and repeat.
BTW, i am using pbasic programming.
Below is the codes i did. I am unable to post the image of my schematic cause i dont know how.
Rich (BB code):
' What's a Microcontroller - testing circuit 6.bs2
' Change digitized analog phototransistor measurement to a binary result.
' Turn an LED on and off.
' Dimming LED.
' {$STAMP BS2}
' {$PBASIC 2.5}
valMax CON 4000
valMin CON 168
time VAR Word
n VAR Byte
PAUSE 1000
DO
GOSUB Rc_Time
GOSUB Display
Rc_Time:
HIGH 2
PAUSE 100
RCTIME 2, 1, time
Display:
time = time MAX valMax MIN valMin
DEBUG HOME, "time = ", DEC5 time
IF time > (valMax - valMin) / 4 * 3 THEN
DEBUG CR, "Turn light onn"
FOR n = 254 TO 179
PWM 14, n, 100
NEXT
ELSEIF time < (valMax - valMin) / 4 THEN
DEBUG CR, "Turn light off"
LOW 14
ENDIF
LOOP
Last edited by a moderator: