View Full Version : Programming Toggle Swiches
ChrisArmour
12-02-2010, 18:46
I am new with labview and have gotten everything but the autonomous done.
i need help trying to set up switches.
i have two switches.
if both of them are on then do no autonomous.
if toggle one on and toggle two off, do autonomous code one
if toggle one is off, 2 on, do autonomous code 2
if both on do automous code three
Mike Betts
12-02-2010, 19:02
Chris,
Read them both in as Boolean then convert to a number. Each will be a zero or a one.
Now multiply #2 by 2 and add to #1. You now have a number ranging from 0 to 3.
Put this into a switch or case statement (depending on your programming language).
You're done...
Mike
Greg McKaskle
12-02-2010, 19:05
There are a couple things to do here. One task is to get toggle switches connected to the Cypress board. You also need to write code. If you want to write the code first, or do the tasks in parallel with someone else, you can disconnect the board from the DS and simply change the digital inputs on the I/O screen directly (this assumes you are using the compatible mode for I/O).
Once this works, or the physical toggles are connected and control the switches on the screen of the DS I/O tab, you want to read those in Autonomous. The VI for this is in palette at WPILib>>Driver Station>>Compatibility I/O>>Get Digital Inputs. It returns an array, and you can retrieve the Booleans from the array using an array indexer or other means. I'd recommend combining the Booleans together into a number and wiring the number to a switch statement around most of your autonomous code. You'll probably find it useful to get the refnums in common code outside the switch, and then put the various autonomous with. You can also make the autonomous routines into subVIs too and simply call them from within the switch statement.
Greg McKaskle
ChrisArmour
13-02-2010, 12:05
Thanks Mike I think we managed to get that code made but I don't think it will quite work with the system we have.
We will have three switches with on/ off positions that will controll three different autonomous modes. The problem is that we are not sure how to connect the switches to the code. We need the code to recieve the position of all the switches form DIO 3-5. We tried to use the select but said that we were using the wrong type of input for "S", but it is the same concept. If button one is on, and others off, then run autonomous for feild section one. If button two on, and others off, then run autonomous for feild section two. If button 3 on and others off, then run autonomous for reild section 3.
Could anyone give me some tips, we are kind off hitting a wall.
Mike Betts
13-02-2010, 16:22
Thanks Mike I think we managed to get that code made but I don't think it will quite work with the system we have.
We will have three switches with on/ off positions that will controll three different autonomous modes. The problem is that we are not sure how to connect the switches to the code. We need the code to recieve the position of all the switches form DIO 3-5. We tried to use the select but said that we were using the wrong type of input for "S", but it is the same concept. If button one is on, and others off, then run autonomous for feild section one. If button two on, and others off, then run autonomous for feild section two. If button 3 on and others off, then run autonomous for reild section 3.
Could anyone give me some tips, we are kind off hitting a wall.
Chris,
I really think that converting to a number and then feedng a switch is far easier and less confusing to do.
Mike
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.