View Full Version : motor and limit switch
ledrac
04-27-2007, 09:19 AM
I am using easyc 2.0 iwant to stop a motor using a limit switch. but for some reason the switch does not stop the motor. i used the if block and made the motor run cw if the switch was ==1 then i said else the limit switch ==0 then i put the motor block in the else as stopped
kingofl337
04-27-2007, 09:52 AM
it should be
while ( 1 )
{
limit = GetDigitalInput ( 1 ) ;
if ( limit == 0 )
{
SetMotor ( 1 , 127 ) ;
}
else
{
SetMotor ( 1 , 255 ) ;
}
}
ledrac
04-27-2007, 12:09 PM
Thanks that worked! I am beginning to get the hang of this. I am progamming a robot with an arm that can raise up and reach forward. once activated by hitting a bumper a motor will lift the arm to a set hieght using shaft encoder, then i want the arm to reach forward using a motor until a limit switch in the hand touches the object (whatever i am picking up) once the limit switch is tripped the arm reach motor should stop and the hand (or gripper motor) should contract on the object, once this happens the arm reach motor should retract, and the motor that raised the arm should lower it to the original position. i dont know enough to get this to work. i have included the program i have so far, there are some bumper sensors in the code that i would like to use in RC mode to stop motors from going too far as well. any help would be greatly appreeciated!
kingofl337
04-27-2007, 12:28 PM
Try watching this and see if it helps.
http://www.intelitekdownloads.com/easyCV2/VexProgramming.wmv
ledrac
04-27-2007, 01:28 PM
I have watched the video, please just give me a couple of lines of code and i will go from there. i have enclosed my robot map
kingofl337
04-27-2007, 02:18 PM
StartEncoder ( 1 ) ;
while ( 1 )
{
Encoder = GetEncoder ( 1 ) ;
if ( Encoder > 300 ) // Encoder is greater than 300
{
SetMotor ( 1 , 127 ) ; // Stop Motor
}
else
{
SetMotor ( 1 , 255 ) ; // Run Motor
}
}
Oh and scissor lifts break hearts :D
ledrac
04-27-2007, 02:30 PM
This robot works with the default program! the lift goes up three feet! I know what you mean though, i have had a lot of trouble with the scissor lift. I am currently placing the sensors on the bot. When i finish i will take some pics.