I have the basic atom lab board, Item Id: B0262
Still learning all the commands and such, I wanted to do the following, just to see if I could get it to work:
when I press a button, LED should turn on. If this same button is released in less than one second, LED should turn off; however ... if button is held for one second or longer, LED should blink 3 times before doing the shutoff. Had a feeling that pulsin command would help, as it could be for measuring button press times, for which then, the value stored into the variable of pulsin command would determine whether to shut off LED or to blink LED.
This is my attempt, but not sure why it was not working, if anybody can enlighten me a bit, I'd appreciate it, and thanks in advance
Code:
input p0 ;button
output p1 ;LED
time_duration var word
main
high p0
high p1
pulsin 0, 0, main, 2000000, time_duration ;time how long button is pressed
if time_duration < 2000000 then LEDOff
if time_duration >= 2000000 then LEDBlink
LEDOff
low p1
goto end1
LEDBlink
low p1
pause 500
high p1
pause 500
low p1
pause 500
high p1
pause 500
low p1
pause 500
high p1
pause 500
low p1
end1
end