Go Down

Topic: 3 Servo With 6 Button Control (Read 757 times) previous topic - next topic

roboticfan101

I have code to have two buttons control a single servo. I need to do this using 3 servos and 6 buttons! Please help! Can someone edit this and make it so i I can do this for 3 servos?!?! Please help!

Code: [Select]

#include <Servo.h>

Servo myservo;

#define leftPin 1
#define rightPin 2

int pos = 90;
int delayPeriod = 9;  // increasing this slows down the servo movement



void setup()
{
  myservo.attach(2);  // attaches the servo on pin 9 to the servo object
  myservo.write(pos); // center the servo
  pinMode(leftPin, HIGH);   // turn on pullup resistors
  pinMode(rightPin, HIGH);
}


void loop()
{
  if(digitalRead(leftPin) == LOW) 
  {                             
   // in steps of 1 degree
   if( pos > 0)
      --pos;
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);                     
  }
  if(digitalRead(rightPin) == LOW) 
  {                             
   if( pos < 180)
       ++pos;
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);       
  }
}

HazardsMind

#1
Feb 23, 2013, 05:18 am Last Edit: Feb 23, 2013, 05:20 am by HazardsMind Reason: 1
Im a little iffy about these, "pinMode(leftPin, HIGH); pinMode(rightPin, HIGH);" but other than that, I dont see the problem. You got one servo to work so, add the rest of the buttons and add more IF statements. Better yet, use arrays, they will shorten your code.

Did you actually write this, or copy it and some extra features?
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

zoomkat

Quote
Better yet, use arrays, they will shorten your code.


Hell, just write it really tight using assembly code!
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

HazardsMind

I know your only joking around, but I actually had to do that once in college. It was not fun.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

roboticfan101

This code works with one servo and 2 buttons. Can someone edit it so I can use 3 servos and 6 buttons. I don't know how to do that!

Go Up