Jump to content


Photo

Toggle ON/OFF


  • Please log in to reply
1 reply to this topic

#1 johannal

johannal

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 14 August 2014 - 01:21 AM

Hi,

 

In the Funduino Robotics programming section, you had this snippet for a kill switch:

 

if(digitalRead(2) == HIGH) // if the push button switch was pressed
{
while(1)
{
leftMotor.write(90);
rightMotor.write(90);
}
}

 

What I wanted to do was to make the button a power toggle switch instead of simply turning off the wheels. From the video, it looks like that is what you had. You set the robot down, and you pushed the button to turn the wheels on. Do you have code for that one?

 


  • 0

#2 Nathan House

Nathan House

    Administrator

  • Administrators
  • 122 posts
  • LocationLynchburg, VA

Posted 14 August 2014 - 01:34 AM

Good question!

 

In the video I had pressed the button/kill switch to stop the robot, then after setting the robot down I pressed the reset button on the Arduino.
 
When you say "power toggle switch," do you mean actually remove power from the robot, or are you just wanting to be able to start and stop it?
 
If you want to completely cut off power to the robot, then it's going to be tricky.. You'll need a slide switch and will have to cut the GND wire on the battery pack and do some soldering. I can walk you through this if it's what you really want to do.
 
On the other hand, if you just want to be able to start and stop the wheels (like the current kill switch, but just with the ability to make it start again using the same button instead of pressing the reset button on the Arduino), then you can slightly modify the kill switch code.
 
Change this code:

if(digitalRead(2) == HIGH) // if the push button switch was pressed
{
    while(1)
    {
        leftMotor.write(90);
        rightMotor.write(90);
    }
}

To this:

if(digitalRead(2) == HIGH) // if the push button switch was pressed
{
    leftMotor.write(90);
    rightMotor.write(90);

    delay(1000); // sleep a second to give the user time to lift their finger off the button

    while(1)
    {
        if(digitalRead(2) == HIGH) // if the push button switch was pressed
        {
            break; // break out of the loop to allow the program to resume execution
        }
    }
}

That's untested, but I think it should work.

 

The advantage of doing this instead of using the reset button on the Arduino (like I did in the video) is that it doesn't restart the program -- it actually continues execution from where it left off. I think I'll change the tutorial to incorporate this after I get a chance to test it out.


  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users