Go Down

Topic: problems with code --> ServoTimeTimer1 (Read 414 times) previous topic - next topic

Pizzamann

Jan 02, 2008, 11:06 pm Last Edit: Jan 02, 2008, 11:23 pm by Pizzamann Reason: 1
I have a problem with some code.
As I already described here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1195136418/0#0.
I try to build a small robot. Currently I'm butting all bits together. Now I'm struggling with some code I tried.

I want to control two servos with the ServoTimeTimer1 from here http://www.arduino.cc/playground/ComponentLib/Servotimetimer1.

Now my problem (please be patient I'm newbie :-/). Here the code I have:



#include <ServoTimeTimer1.h>

#define servoPin1 9
#define servoPin2 10
#define potPin1 0
#define potPin2 1

ServoTimeTimer1 servo1;
ServoTimeTimer1 servo2;

int myPot1 = 0;
int myPot2 = 0;
int ledPin = 13;                // LED connected to digital pin 13

void setup ()
{
 servo1.attach(servoPin1);
 servo2.attach(servoPin2);
 pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void ledBlink()
{
 //BLINK1
 digitalWrite(ledPin, HIGH);   // sets the LED on
 delay(1000);                  // waits for a second
 //BLINK2
 digitalWrite(ledPin, LOW);    // sets the LED off
 delay(1000);                  // waits for a second
}

void loop()
{
   for (myPot1=0; myPot1<=180;  myPot++)
   {
     servo1.write((myPot1*2)+500);
     ledBlink();
   }
   for (myPot2=0; myPot2<=180;  myPot2++)
   {
     servo2.write((myPot2*2)+500);
     ledBlink();
   }
   for (myPot1=180; myPot1>=0;  myPot1++)
   {
     servo1.write((myPot1*2)+500);
     ledBlink();
   }
   for (myPot2=180; myPot2>=0;  myPot2++)
   {
     servo2.write((myPot2*2)+500);
     ledBlink();
   }
}




Here my problem:

In function 'void loop()':
error: 'myPot' was not declared in this scope


Can you please help?  :-?

Greg

mem

#1
Jan 02, 2008, 11:39 pm Last Edit: Jan 02, 2008, 11:46 pm by mem Reason: 1
the clue to the problem is in the error message: "myPot was not declared..."

Code: [Select]
for (myPot1=0; myPot1<=180;  myPot++)

in this for loop you are incrementing a variable called myPot when you intend myPot1.

BTW, I think servo2.write() expects a value between 500 and 2500, not an angle. So you may want to do something like:

for (myPot1=500; myPot1 <= 2500;  myPot1++)

in fact, many servos expect a range between 1000 and 2000 microseconds so I would start off with that and increase the range after verifying that the servos don't hit the end stops.






Pizzamann

#2
Jan 02, 2008, 11:50 pm Last Edit: Jan 02, 2008, 11:52 pm by Pizzamann Reason: 1
:o
I'm stupid
>:(

Thanks for your hint!

Greg

Go Up