im extremely confused about buttons. ive read the section in the basic manual several times, and played with them a little. however, ive gotten two conflicting definitions of the last parameter on target state. 1) that is says which state the button should be in in order to branch 2) that when in downstate, 0 it doesnt branch and 1 it does. also, ive been trying to program a kill switch in that is basically a button statement that says when the button is pressed, goto a subroutine that puts the program into an infinite loop. ive written this program before for the edu robot and had it work, and i also have last year's code which is working. but mine isnt, and i cant figure out why.the program goes into the kill switch subroutine whether the button is pressed or not, and wont get out of the subroutine. here is the code:
the pin is p4_sw_aux1, and ive already tested the mechanical switch and it works physically.
**ive been informed that the button command is not valid for us. any thoughts?
*in main section
BUTTON p4_sw_aux1, 0, 255, 0, wksp, 0, KillSwitch:
*in subroutine section
KillSwitch:
Serin COMA\COMB, INBAUD, [oi_swA,oi_swB,rc_swA,rc_swB,p2_x,p1_x,p4_x,p3_x,P
B_mode,packet_num,p2_y,p1_y,p4_y,p3_y,p2_wheel,p1_
wheel,p4_wheel,p3_wheel]
BUTTON p4_sw_aux1, 0, 255, 0, wksp,1, Mainloop:
Serout USERCPU, OUTBAUD, [255,255,127,0,127, 0, 127,127,127,127,127,127,127,127,127,127,127,127,12
7,127]
GOTO KillSwitch:
That is correct, the BUTTON command is not valid as it relies on having a switch hooked up to one of the pins on the Stamp, which they aren't. What you need is a simple if statement.
2.0:
...
if p4_sw_aux1=0 then dontKill
gosub killLoop
dontKill:
...
serout
goto mainloop
killLoop:
if p4_sw_aux1=1 then keepKilling
return
keepKilling:
Serin...
Serout...
goto killLoop:
2.5:
...
if p4_sw_aux1=1 then gosub killLoop
...
serout
loop
killLoop:
do
serin...
serout...
while p4_sw_aux1=1
return
then why did my other programs work? on the operator interface, aren't all the pins connected? how else can information from the joysticks and everything else be used? isnt the debug program supposed to have names for all the pins so we can use them? id appreciate a more detailed explanation cause im still kinda confused.
also, i have another question not really connected. how different are the analog inputs treated than the digital. my point: if i run out of digital inputs, could i make the computer pretend the analog inputs are digital? so i could use more sensors and limit swtiches.
thanks
Originally posted by rosebud
then why did my other programs work? on the operator interface, aren't all the pins connected? how else can information from the joysticks and everything else be used? isnt the debug program supposed to have names for all the pins so we can use them? id appreciate a more detailed explanation cause im still kinda confused.
also, i have another question not really connected. how different are the analog inputs treated than the digital. my point: if i run out of digital inputs, could i make the computer pretend the analog inputs are digital? so i could use more sensors and limit swtiches.
thanks
It's a complex issue, but here's a quick explanation of why you can't use BUTTON:
The BASIC Stamp that we use (the 2sx) is designed for a whole lot more than just the robot contollers. In other applications, EE guys will connect a switch directly between ground, +5V and a pin on the Stamp.
This is the intention of the BUTTON command. The InnovationFirst controllers, however, do not work this way. All of the switches, analogs, etc, are connected to a separate uP inside the RC. How exactly they are connected is not documented, but it doesn't really matter. What matters is that this separate uP processes all the inputs from both the OI and the RC. This uP then connects to the Stamp via a standard RS-232 signal over one of the pins. This is where the Serin/Serout comes from.
The only things directly connected to the Stamp that you should EVER touch are pins 7-15. Pin 7 is the basic run LED, and 8-15 are the various other LEDs you can control. Everything else comes in mass through the serin command and becomes individual bits in variables instead of actual pins.
As for using an analog for a digital switch, you can definately do it. Two years ago, we ran out of switches on the OI, so I wired a little toggle switch between +5V and one of the analog ins. There was also an LED in series with it, but that doesn't matter. When the switch is off, the analog will read 127. When it is on, it will read something else. What that something else is depends on the amount of resistance in your circuit. In my case the LED caused us to get a value of 160-ish when on and 127 when off.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.