Professional Documents
Culture Documents
0 and counts those activations. When five activations have been counted a LED on output pin B.1 will be set. The 'pause 100' acts as a contact de-bounce; if it is removed contact bouncing may cause the LED to be lit prematurely. init: let b0 = 0
add:
pause 100 let b0 = b0 + 1 if b0 < 5 then main high B.1 goto main
; short delay
KEYPAD This program demonstrates example code for the CHI008 Keypad Lock kit using a PICAXE-18M2 #picaxe 18m2
;output 7 - FET to drive solenoid bolt ;output 6 - piezo sounder ;output 4,5 - bicolour LED ;output 3 - row 4 ;output 2 - row 3 ;output 1 - row 2
;output 0 - row 1
; *** now scan each row in turn *** ; *** by setting only 1 row (and LED) high *** ; *** if a switch is hit jump call score sub below ***
gosub key_test
goto scan
; *** Score sub procedure. *** ; *** return straight away if no key pressed ***
key_test: if pinC.0 = 1 then add1 if pinC.1 = 1 then add2 if pinC.2 = 1 then add3 return
; *** key value will already be 0, 3, 6, or 9 *** ; *** so add 1, 2 or 3 to this value ***
sound B.6,(60,50)
; *** Now increase position counter by 1 *** ; *** and test for 1st, 2nd 3rd or 4th push ***
if key_pos = 1 then test1 if key_pos = 2 then test2 if key_pos = 3 then test3 ; if key_pos = 4 then test4
; *** Now test the value for each position individually *** ; *** If value is wrong restart, if correct loop until *** ; *** fourth go. If fourth is correct open lock! ***
; *** Got here so open lock and set LED green for 5 sec ***
; *** Not correct value so reset position counter then return ***
continue:
return
SERIAL OLED Reads the temperature from a DS18B20 and displays the result on the LCD low b.2 pause 500 main: readtemp c.1, b0 bintoascii b0, b1,b2,b3 digits serout b.2, n2400, ( 254, $80 ) serout b.2, n2400, ( "Temperature" ) serout b.2, n2400, ( 254, $C0 ) serout b.2, n2400, ( b1, b2, b3, "C" ) pause 1000 goto main ; First line of display ; Display "Temperature" ; Second line of display ; Display the temperature ; Initialise OLED output ; Waif for OLED to initialise ; Read DS18B20 on pin C.1 ; Convert temperature to ascii
INPUT PIN symbol MotA1 = 0 symbol MotA2 = 1 symbol MotB1 = 2 symbol MotB2 = 4 ;00 forward motor one, 01 backward motor 1, 10 forward motor 2, 11 backward motor 2 main: if input 3 = 0 then goto motorA ; jump to flsh if pin0 is high
end if goto main ; else loop back to start motorA:;run motor A pause 2000 ; wait 0.2 seconds if input 3 = 0 then goto goforward goforward: High MotA1 Low MotA2 ; switch off output B.1 end if goto main ; loop back to start