I need to create an array for my maxbotix sonar sensor. I'm using 6 maxsonar - AnalogPins 0 to 5. Each sonar controls a servo. Ex. Servo0 attach to digital pin 2 goes with analogpin 0 maxsonar.
Servo opens when analog 0 -if (analogRead(0)< 110){
else servo is close and always sends pin val- to Max Jitter.
I'm also using Max Jitter to get the analog pin data to control video and audio.
Here is the code so far- Awol help with the servo array-
If you have any suggestions please do reply. THANKS
#include <Servo.h>
#define N_SERVOS 6
Servo myServo [N_SERVOS];
const byte servoPin [N_SERVOS] = {2, 3, 4, 5, 6, 7};
int pos = 0;
int pos2 = 0;
void setup() {
Serial.begin(9600);
for (int i = 0; i < N_SERVOS; ++i) {
myServo [i].attach (servoPin [i]);
}
}
void loop() {
[glow] if (analogRead(0)< 110){
Serial.print (analogRead(0));
Serial.println();
moveTo(170);
}
else{
Serial.print (analogRead(0));[/glow]
Serial.println();
moveTo(10);
}
}
void moveTo(int newPosition){
int degreesPerStep = 1; // decrease this to slow movement
int currentPos = myServo.read();
int movement = newPosition - currentPos; // the number of degrees to move
if(movement < 0){
while(currentPos > newPosition){
currentPos = currentPos - degreesPerStep;
myServo.write( currentPos);
delay(20);
}
}
else{ // movement is >0 )
while(currentPos < newPosition){
currentPos = currentPos + degreesPerStep;
myServo.write( currentPos);
delay(20);
}
}
}
I need to create an array for my maxbotix sonar sensor.
I just need to create an array for the 6 maxbotix sonars that I'm using.
I already have the servos array and I tried to use the examples (array/loop) in arduino and it did not work.
I dont have the code in this computer- I'm in school. I can post it later.
I tried something similar to the arrays example in arduino-
int [glow]___?[/glow][] = {0, 1, 2, 3, 4, 5 }; // an array of pin numbers
int pinCount = 6;
I just need that each (6) sonar to control each (6) servo (sonar 1 = servo 1) and send the analog readings to max jitter (which is working).
When the sonar goes to 110 or less the servo motor opens 170 degrees and stays open until the sonar sends more than 110-the servo goes to 10 degrees and stays close.
The first code work perfectly with one servo and one sonar. I only need to figure out how to write the other 5 servos and sonar's.
I already did the servo array that you kindly suggested, but I need to do the same with the sonar- and see if it works.
Thanks, larissa