; Lesson-012-Photoresistor-LDR.bas #picaxe 20M2 ; Define the µProcessor IC Type ; Declare Constants & Variables ; Photresistor = A.0 ; My ambient light was about 190 yours could be different ; so watch the debug screen to find your ambient light level ; and set that as the condition level. symbol RLED = B.7 symbol GLED = B.6 symbol BLED = B.5 symbol i = b0 ; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * * * * * * * do readadc B.0, b1 ; read the value from variable b1 debug b1 ; Display variable b1 in debug window if b1 < 200 then gosub green ; IF its dark turn ON the green LED if b1 > 200 then gosub red ; IF its light turn ON the red LED pause 500 ; wait a short while loop ; END Main Body * * * * * * * * * * * * * * * * * * * * * * * * * ** end ; BEGIN Subroutines * * * * * * * * * * * * * * * * * * * * * * * * red: low RLED ; RED ON high GLED ; Green OFF high BLED ; Blue OFF return green: high RLED ; RED OFF low GLED ; Green ON high BLED ; Blue OFF return blue: high RLED ; RED OFF high GLED ; Green OFF low BLED ; Blue ON return Police: For i = 0 to 4 gosub red pause 50 gosub LEDsOFF pause 50 gosub red pause 50 gosub LEDsOFF pause 100 gosub blue pause 50 gosub LEDsOFF pause 50 gosub blue pause 50 gosub LEDsOFF pause 100 next i return LEDsOFF: high RLED ; switch RED OFF high GLED ; switch Green OFF HIGH BLED ; switch Blue OFF return ; END Subroutines * * * * * * * * * * * * * * * * * * * * * * * ** end