Go Down

Topic: Need some help for a science project. (Read 10 times) previous topic - next topic

Falchion

Woops. I actually meant the ON LED.  :smiley-roll:
Robots are cool.

arduinohabib

You must be careful when that happens. It means there's a short circuit somewhere.
What is man's best friend? The breadboard!

Falchion

This is getting out of hand... I'm doing everything it says in this tutorial, (http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html) and it still isn't working... I have to have this thing done by February 4th, and this is worth a TON of points, so if it doesn't get done, my grade will suffer...
Robots are cool.

Falchion

Wait a second... How do I add a servo? Here's the line of code.
Quote

  // attach the servos
  for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
  {
    myServos[nServo].attach(SERVO_TO_PIN(nServo));
  }

Robots are cool.

JimboZA

#89
Jan 26, 2013, 06:05 am Last Edit: Jan 26, 2013, 06:13 am by JimboZA Reason: 1
At the top of DuaneB's code it says this...

Code: [Select]
#include <Servo.h>
// Sample sketch for driving 12 Servos from an Arduino UNO, servos are attached to digital pins 2,3,4,5,6,7,8,9,10,11,12,13

#define CONNECTED_SERVOS 12


It sweeps a whole load of servos on those pins....

So to attach servos to the board, you control them by putting their yellow / orange wires into those pins.

(The #define CONNECTED_SERVOS 12 tells it there are 12 and you could reduce that number I guess to just have however servos you have)

This part:

Code: [Select]
// attach the servos
 for(int nServo = 0;nServo < CONNECTED_SERVOS;nServo++)
 {
   myServos[nServo].attach(SERVO_TO_PIN(nServo));
 }



... uses the value of "CONNECTED_SERVOS" which is 12 if you didn't alter it at the top as the upper limit of a counter in a loop and runs the "attach" line as many times as you have servos to as many pins as there are servos.

This is an automated way of doing what I showed you a few posts back where I had something like myservo.attach and anotherservo.attach. The myServos[nServo] in Duane's code is a way of automating say myServos5 and myServos9 or whatever where nServo is a variable instead of hardcoding the same line a stack of times each with a different number.
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Go Up