Author |
Message |
derpfac3
Rookie
Joined: Wed Feb 15, 2012 4:44 am Posts: 2
|
 Making a toggle???
Hey, I always used this to make a motor spin with a button. But now I have to make it so I press the button once than it goes spinning at 50% and if I press the button again it stops. i hope anybody can help. 
|
Wed Feb 15, 2012 4:54 am |
|
 |
derpfac3
Rookie
Joined: Wed Feb 15, 2012 4:44 am Posts: 2
|
 Re: Making a toggle???
It works tnx a lot but now we have a problem because of this code the rest of the program stops working and i cant use a while(1) command cuz that is activating the robot on command so we cant use it without a different programm telling it to run. so i tried to remove the while true command and than the command doesnt work i am a noob programmer :} 
|
Wed Feb 15, 2012 9:17 am |
|
 |
rkrishnan2012
Rookie
Joined: Sun Feb 27, 2011 3:41 pm Posts: 20
|
 Re: Making a toggle???
It won't work because you need to adapt it into a seperate task....
|
Fri Mar 09, 2012 12:20 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Making a toggle???
No, you don't need a separate task. You just need to put your other stuff inside the same while loop.
|
Fri Mar 09, 2012 1:52 pm |
|
 |
rkrishnan2012
Rookie
Joined: Sun Feb 27, 2011 3:41 pm Posts: 20
|
 Re: Making a toggle???
right but when we do that, everything will get delayed by 100ms...Probably not a lot though 
|
Mon Mar 12, 2012 10:59 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Making a toggle???
It is recommended to do some delay between each loop but it doesn't have to be 100 msec. The delay will help with the button debounce. If your other stuff needs to be processed more often then the minimum debounce time, you could process the button once every n loops. Then you can do a 10 msec delay or less in each loop.
|
Tue Mar 13, 2012 12:41 am |
|
 |
rkrishnan2012
Rookie
Joined: Sun Feb 27, 2011 3:41 pm Posts: 20
|
 Re: Making a toggle???
we got around this problem but using a timer to check whether it has been 200ms since the last check. Then if so, you reset the timer and do the cycle again.
|
Thu Apr 19, 2012 12:08 am |
|
 |
Michael120
Rookie
Joined: Mon Feb 21, 2011 3:40 pm Posts: 15
|
 Re: Making a toggle???
Sorry if this is old; but wouldn't it work if you use: What would be the advantages/disadvantages of either?
|
Thu May 17, 2012 9:02 pm |
|
 |
rkrishnan2012
Rookie
Joined: Sun Feb 27, 2011 3:41 pm Posts: 20
|
 Re: Making a toggle???
Ah! that's actually a nice way of doing it...
|
Sun Aug 12, 2012 3:31 pm |
|
 |
Michael120
Rookie
Joined: Mon Feb 21, 2011 3:40 pm Posts: 15
|
 Re: Making a toggle???
I sometimes find that simple is better. 
|
Sun Aug 19, 2012 10:56 am |
|
 |
hmwoody24
Rookie
Joined: Tue Aug 21, 2012 2:36 pm Posts: 1
|
 Re: Making a toggle???
What's a toggle?
|
Tue Aug 21, 2012 8:34 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Making a toggle???
A toggle is like a button that when you press it, it alternatingly switches something on or off.
- Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Wed Aug 22, 2012 2:46 am |
|
|