If this question has already been asked please point me to the correct post because I have not found it yet.
The Mini-ABB Bot Board has three LEDs, A, B, and C, with three buttons underneath. I assume I can store up to three various programs into those slots. How do I do this? Is there somewhere I could veiw the syntax for storing the programs. Thanks in Advance.
if (butA = BUTTON_DOWN) AND (prev_butA = BUTTON_UP) then
nn = nn + 1
sound P9,[5\2500]
low P9
endif
if (butB = BUTTON_DOWN) AND (prev_butB = BUTTON_UP) then
nn = nn - 1
sound P9,[10\1000]
low P9
endif
if (butC = BUTTON_DOWN) AND (prev_butC = BUTTON_UP) then
nn = 0
sound P9,[10\4000]
low P9
endif
ledA = nn.BIT0
ledB = nn.BIT1
ledC = nn.BIT2
if ( nn.BIT0 = 1 ) then
high p0
high p8
high p12
else
low p0
low p8
low p12
endif
if ( nn.BIT1 = 1 ) then
high p1
high p13
else
low p1
low p13
endif
if ( nn.BIT2 = 1 ) then
high p2
high p10
high p14
else
low p2
low p10
low p14
endif
if ( nn.BIT3 = 1 ) then
high p3
high p7
high p11
high p15
else
low p3
low p7
low p11
low p15
endif
pause 50
prev_butA = butA
prev_butB = butB
prev_butC = butC
gosub button_led_control
goto main
'Subroutine to read the buttons and control the LEDs. Button states are put in
'variables butA, butB, and butC. LED states are read from variables ledA, ledB,
'and ledC.
button_led_control:
'Make P4-P6 inputs to read buttons. This turns the LEDs off briefly
input p4
input p5
input p6
butA = IN4
butB = IN5
butC = IN6
'Output LOW to each LED that should be on
if ledA = 1 then
low p4
endif
if ledB = 1 then
low p5
endif
if ledC = 1 then
low p6
endif
I wish the buttons and LEDs were accessible when the bot board is covered. I have my bot board (on an SES carrier) on the second deck of Octabot rather than the top deck (to make it more cat proof).
I am guessing I could probably use that code with external buttons I attach though. Is that right? I’ve been thinking about possible attaching a small matrix keyboard.
Jim could answer this a lot better than me, but I will take a stab.
You should be able to use separate buttons. I have not done it yet on this board, but I have done it on other controllers. The one problem you run into is the need to debounce the input. When you press a button, the value may bounce high and low before it settles. One easy (not necessarily the most reliable) way is to put a small pause in before you check the state of the button again. The sound command in Jim’s sample code will take care of that. You might also try the Basic Atom’s Button command to handle it for you.
As for matrix keypads, the one that I used was a little more fun to hook up. If I remember correctly mine was a 4x4 keypad, and required 8 inputs. At some reasonable interval, you had to individually pulse each row(or column) and then check each of the 4 inputs for the individual columns and see if any of them went high (or low). This would give you a row/column of which button was pressed. I hope this makes sense. I don’t have the code with me right now so I may have missed some details. This same keypad was later hooked up to a Devantech LCD display that used I2C for communications for both outputting to the LCD as well as detecting if any buttons were pressed. In the end I gave up using this display as I found the I2C input to be a bit flakey and it would hang the I2C bus and only power cycling the CPU would clear it. Maybe they have improved it sinse then!
I understand debouncing switches - did it many times in various electronics courses. I can also do what Jim showed me to do when reading the IRPD - I can just read it multiple times and take the last reading as the real deal. A simple for loop handles this nicely.
I will be checking this out when the time comes to work with buttons.
This should not be a problem and can be handled in a subroutine quite nicely, the same way I do for checking the IRPD. In fact, most of my code for Octabot is already in subroutines now.
I have been working on Octabot today and have the scanning behavior almost tweaked to what I want. Octabot can also switch in and out of scanning mode as needed - this is exactly what I want for using the pan/tilt scanning base when I get it built and installed.