One nice feature of the PICAXE 18X is to be able to read analog components, by connecting them to an input pin. This will have to be either input0 (pin 17) or input1 (pin 18) as they have ADC support.
This is how the meter is going to work. The LDR will be used by the PICAXE to determine the amount of light. Based on the amount of light LEDs will be lit or unlit. The more light, the more LEDs will be lit.
For the following circuit we will require these items:
1 x 9V Battery
1 x LDR
1 x 10 kOhm resistor (brrown, black, orange)
1 x 4.7 kOhm resistor (I still use three)
8 x 1 kOhm resistor (brown, black, red)
8 x C547B transistor
3 x green LED
3 x yellow LED
2 x red LED
Ok, here we go. Step by step:
1. Place the PICAXE on the board, like the last time.
2. Put the 8 LEDs on the board
4. For each LED add a transistor to the board. Whatch carefully how to connect them.
main:
readadc 1, b0 'Read the amount of light 0=dark 255=very much
'Is it very bright? put led 7 on
if b0 > 230 then
high 7
else
low 7
end if
'Is it less very bright? put led 6 on
if b0 > 200 then
high 6
else
low 6
end if
'Is it bright? put led 5 on
if b0 > 180 then
high 5
else
low 5
end if
'Is it medium bright? put led 4 on
if b0 > 150 then
high 4
else
low 4
end if
'Is it below medium? put led 3 on
if b0 > 120 then
high 3
else
low 3
end if
'Is it between dark and medium bright? put led 2 on
if b0 > 90 then
high 2
else
low 2
end if
'Is it less dark? put led 1 on
if b0 > 60 then
high 1
else
low 1
end if
'Is it quite dark? put led 0 on
if b0 > 30 then
high 0
else
low 0
end if
goto main
This is the result:
Geen opmerkingen:
Een reactie posten