0
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #15 on: November 07, 2009, 06:01:13 pm » |
still getting and error
*analogRead(potpins[0]); //
*error: expected constructor, destructor, or type conversion before '(' token In function 'void loop()':
BTW I'm using 5k potentiometers, so I need to map the 0, 511 values for the potentiometer to 0, 179 of the servo position.
|
|
|
|
|
Logged
|
|
|
|
|
Spokane, Washington
Offline
God Member
Karma: 0
Posts: 686
My name is Bob, and I'm an addict.
|
 |
« Reply #16 on: November 07, 2009, 06:05:30 pm » |
I'm not sure why you're getting errors.. did you remove the two analogReads like I showed? Well I commented them out..
Yup, that's the error.. make sure the two analogReads before your SETUP are commented out... or better yet, just delete them completely! Once I remove the comment lines for them, I get the same exact error.
You don't need the analogRead before Setup because.. well.. it does no good! You read all 9 sensors within about .2 seconds inside the loop anyways.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #17 on: November 07, 2009, 06:14:30 pm » |
ok, now it works.
But anybody have anything for the "map" function to translate the 5k potentiometer to 180 positions on the servo?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 313
Posts: 35487
Seattle, WA USA
|
 |
« Reply #18 on: November 07, 2009, 06:22:43 pm » |
The map function call looks like this:
int newValue = map(value, fromLow, fromHigh, toLow, toHigh);
fromLow and fromHigh are the range to map from (0 to 1023 in your case). toLow and toHigh are the range to map to (0 to 180 in your case).
|
|
|
|
|
Logged
|
|
|
|
|
Spokane, Washington
Offline
God Member
Karma: 0
Posts: 686
My name is Bob, and I'm an addict.
|
 |
« Reply #19 on: November 07, 2009, 06:22:53 pm » |
It won't matter what kind of resistance you're using, it will end up reading the same as long as it's a voltage divider (potentiometer). potvals - = map(analogRead(potpins
- ), 0, 1023, 0, 179);
That's got to be inside the loop, replace: potvals - = analogRead(potpins
- ); // remove completely
with: potvals - = map(analogRead(potpins
- ), 0, 1023, 0, 179);
It needs to be the same position. Also, now when you want to write the values to a servo, you can use: servo0.Write(potvals[0]); servo1.Write(potvals[1]); // etc. Hopefully this helps!:)
|
|
|
|
|
Logged
|
|
|
|
|
Norway@Oslo
Offline
Edison Member
Karma: 11
Posts: 2033
loveArduino(true);
|
 |
« Reply #20 on: November 07, 2009, 06:28:53 pm » |
To really see the benefit of using arrays, I would have a Servo array as well. That way you can do: const byte NUMBER_OF_SERVOS = 10;
//later in code //set all servos position equal to the potvals for (byte i=0; i<NUMBER_OF_SERVOS; i++){ servo[i].write(potvals[i]); } 
|
|
|
|
|
Logged
|
|
|
|
|
Spokane, Washington
Offline
God Member
Karma: 0
Posts: 686
My name is Bob, and I'm an addict.
|
 |
« Reply #21 on: November 07, 2009, 06:32:38 pm » |
Hey.... I was feeling semi-smart here, thanks for ruining it Alpha!  I'm still learning, slowly but surely... haha, seems that helping others learn, speeds up the learning process on my end as well!  But yes, arrays are something to definitely get used to, save you alot of time/typing/code/space/sanity! There are ALOT of tutorials with C++, alot of good videos that can explain alot, in a bit more depth than most of us are willing to type out!:D
|
|
|
|
|
Logged
|
|
|
|
|
Norway@Oslo
Offline
Edison Member
Karma: 11
Posts: 2033
loveArduino(true);
|
 |
« Reply #22 on: November 07, 2009, 07:28:20 pm » |
Hey! We addicts have to support each other, you know. [my sign. used to say that I was an arduinoAddict] I just spon off your ideas, no glory in that (maybe if you ask Micr*soft). 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #23 on: November 07, 2009, 07:59:45 pm » |
Ok, I don't get what Alpha wrote :p Well, I should of probably defined what I am trying to do before anything lol I'm trying to control 10 servos with 10 5K potentiometers each with assigned to each other and able to move independently (or physically appearing to do so). The megaservo example looks similar to what Alpha posted, but that just moves multiple servos with one potentiometer, and assume that the code is similar to physically wiring the servos in parallel. And anyone know how to patch the IDE 17 on a mac for the Arduino Mega bug? EDIT: Another thing; this really confuses me (maybe I'm just thinking too much :p). All the examples I've seen with a analog input and digital output, just has the pins/objects assigned just by using the pin numbers. Where I'm confused is to how it knows if you are referring to an analog pin or a digital pin? like in this example int the learning section: // Controlling a servo position using a potentiometer (variable resistor) // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin
void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }
void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }
|
|
|
|
« Last Edit: November 07, 2009, 08:07:04 pm by mtktm »
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 50
Arduino rocks
|
 |
« Reply #24 on: November 07, 2009, 08:43:18 pm » |
I don't know if you caught this, but your "potpins" and "potvals" variables aren't the same size. If you're trying to use 10 inputs, potpins will be 0 to 9 (which is ten numbers), and your potvals should be an array with 10 values (potvals[10]). Then, when you read, you can do for(i=0; i<10; i++). This reads values 0 through 9 (10 values). You have to remember you're starting your counting from 0 now, not from 1 like humans are used to. To patch the library, you'll have to edit the file wiring_analog.c. Instructions on what to do are here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250970792 I don't know where the arduino lives on a mac, so you can probably just do a search for the file. As for which pins you read, that's built into the Arduino IDE. analogRead() knows which pins are the analog pins, and digitalRead() knows which pins are digital. The Arduino guys did all of that coordination for you, so digitalRead(10) reads from the digital pin with the 10 silkscreened next to it.
|
|
|
|
« Last Edit: November 07, 2009, 08:43:50 pm by jpgr87 »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #25 on: November 07, 2009, 09:05:16 pm » |
jpgr87: Yes I'm pretty sure we know. We were just focusing on the errors that I was posting.
That link does nothing for me because I'm on a mac and the wiring_analog.c file isn't found just by a simple search. Its most likely in a compressed file somewhere, which I am unable to find.
EDIT: well, I found it and it appears to be already patched :p
|
|
|
|
« Last Edit: November 07, 2009, 09:44:26 pm by mtktm »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 47
Arduino rocks
|
 |
« Reply #26 on: November 08, 2009, 02:17:51 pm » |
Before you start. are you going to be using the built in power supply for all of this? You may overload the regulator.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #27 on: November 08, 2009, 07:07:52 pm » |
I already built a 5v regulator that will step down my 18v batter pack to 5v.
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #28 on: November 08, 2009, 11:11:25 pm » |
I'm trying to control 10 servos with 10 5K potentiometers each with assigned to each other and able to move independently (or physically appearing to do so).
The megaservo example looks similar to what Alpha posted, but that just moves multiple servos with one potentiometer The MegaServo example reads one pot and uses that value to control all the servos. AlhpaBeta's post shows how to change it so that a different pot can be used for of each servo. Here is the full sketch with that change: #include <Servo.h> #define NBR_SERVOS 10 // the number of servos #define FIRST_SERVO_PIN 2 // this first of consecutive digital pins used for servos
Servo Servos[NBR_SERVOS] ; // an array of servo objects
void setup() { // attach all 10 servos to digital pins starting from 2 for( int i =0; i < NBR_SERVOS; i++) Servos[i].attach( FIRST_SERVO_PIN +i, 800, 2200); } void loop() { int pos = 0; // variable to store the servo position
for( int i =0; i <NBR_SERVOS; i++) { pos = analogRead(i); // read a value from pins 0 to 9 Servos[i].write( map(pos, 0,1023,0,180)); // and write the value to the servo } delay(15); }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #29 on: November 10, 2009, 01:34:08 pm » |
Thanks!!
I'll try it out as soon as my board comes in. Should be tomorrow or the next day.
hope I don't burn out something :p
|
|
|
|
« Last Edit: November 10, 2009, 01:51:35 pm by mtktm »
|
Logged
|
|
|
|
|
|