ok what I'm atempting to do is write a simple program that blinks some LEDs for now, i figure this will be the best way to learn. what i would like to do for example is:
''(solid light mode & default)
start:
If PIN_4 = on then
(do stuff once)
goto mode_1
end if
set PIN_2 on
goto start
''(blink light mode slow)
mode_2:
If PIN_4 = on then
(do stuff once)
goto mode_3
end if
set PIN_2 on
wait 500 ms
set PIN_2 off
wait 500 ms
goto mode_2 'go back to top of mode_1
''''(blink light mode faster)
mode_3:
If PIN_4 = on then
(do stuff once)
goto Start
end if
set PIN_2 on
wait 250 ms
set PIN_2 off
wait 250 ms
goto mode_3 'go back to top of mode_2
I havent got it working right and i think what it is doing is reading the button press to fast (skiping over modes) i dont think its even gettin back to the start.. i have tried to find info on how to fix it and all i find is ppl talkin about debounce? what is debounce and how do i do it? if someone has an example of code that works like this and is willing for the world to see please help me out
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please don't use 'If PIN_4 = On Then', it produces some ugly looking assembler. Use, 'If PIN_4 On Then'.
If you look back to the 'Interrupt' post in help, I gave a crude debounce routine in GCBasic. An internal pullup is setup for the button, and the pin is setup as an input. In this configuration, your 'If PIN_4 On Then' should be changed to check for a low or 'If PIN_4 Off Then'. Using the 'wait 10ms' gives the button time to settle into a steady logic condition.
When using a button as an input it should be in a defined state by pulling it up to Vdd or pulling it down to Vss with a 10k resistor. If you have your button is pulled down to Vss then you can ignore my comments about 'If PIN_4 On Then'.
Be sure to comment out (do stuff once). Good idea to use a goto start at the end of the code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ok what I'm atempting to do is write a simple program that blinks some LEDs for now, i figure this will be the best way to learn. what i would like to do for example is:
''(solid light mode & default)
start:
If PIN_4 = on then
(do stuff once)
goto mode_1
end if
set PIN_2 on
goto start
''(blink light mode slow)
mode_2:
If PIN_4 = on then
(do stuff once)
goto mode_3
end if
set PIN_2 on
wait 500 ms
set PIN_2 off
wait 500 ms
goto mode_2 'go back to top of mode_1
''''(blink light mode faster)
mode_3:
If PIN_4 = on then
(do stuff once)
goto Start
end if
set PIN_2 on
wait 250 ms
set PIN_2 off
wait 250 ms
goto mode_3 'go back to top of mode_2
I havent got it working right and i think what it is doing is reading the button press to fast (skiping over modes) i dont think its even gettin back to the start.. i have tried to find info on how to fix it and all i find is ppl talkin about debounce? what is debounce and how do i do it? if someone has an example of code that works like this and is willing for the world to see please help me out
oops, this wasnt the problem with it i just screwed up re-typing it into the thread. it should look like this:
''(solid light mode & default)
start:
If PIN_4 = on then
(do stuff once)
goto mode_2
end if
set PIN_2 on
goto start
''(blink light mode slow)
mode_2:
If PIN_4 = on then
(do stuff once)
goto mode_3
end if
set PIN_2 on
wait 500 ms
set PIN_2 off
wait 500 ms
goto mode_2 'go back to top of mode_2
''''(blink light mode faster)
mode_3:
If PIN_4 = on then
(do stuff once)
goto Start
end if
set PIN_2 on
wait 250 ms
set PIN_2 off
wait 250 ms
goto mode_3 'go back to top of mode_3
Not enough info to see where the problem is, can you post the whole code? What errors are you getting?
A quick search or wiki will explain how to debounce your button or switch like http://www.ikalogic.com/debouncing.php
Please don't use 'If PIN_4 = On Then', it produces some ugly looking assembler. Use, 'If PIN_4 On Then'.
If you look back to the 'Interrupt' post in help, I gave a crude debounce routine in GCBasic. An internal pullup is setup for the button, and the pin is setup as an input. In this configuration, your 'If PIN_4 On Then' should be changed to check for a low or 'If PIN_4 Off Then'. Using the 'wait 10ms' gives the button time to settle into a steady logic condition.
When using a button as an input it should be in a defined state by pulling it up to Vdd or pulling it down to Vss with a 10k resistor. If you have your button is pulled down to Vss then you can ignore my comments about 'If PIN_4 On Then'.
Be sure to comment out (do stuff once). Good idea to use a goto start at the end of the code.