Hello everyone - I'm new here so first I'd like to introduce myself.
My name is Nick - I'm an architecture graduate student using physical computing to investigate interactive spaces and responsive materials and how they apply to architectural concepts and future construction methods.
Ok my question - I'm building a little prototype and will eventually need 18 servos running independently responding to various analog input -
right now I just need to move one, or two motors to three specific locations - min, middle , and max. I'm using a simple potentiometer and 180 degree servos.
I've gotten the servo to run alongside of the potentiometer, but I'd rather see it only move when specific values are hit (eg, potentiometer is at midway - the servo runs from min to mid rotation and stops)
heres some code that doesn't seem to work.... nothing moves! I was hoping you guys could share some insight to maybe illuminate things I may be doing incorrectly - as well as possibly offer places to get some source code that works so I could manipulate it and learn more of arduino coding - I'm new to the platform! Cheers and thanks in advance!
int servoPin = 12; // Control pin for servo motor
int minPulse = 500; // Minimum servo position
int maxPulse = 2500; // Maximum servo position
int pulse = 0; // Amount to pulse the servo
int analogValue = 0;
int analogPin = 2;
int myVar = 0;
void newline(void);
void pulsout( int servoPin, int pulse);
void turnServo(int angle);
void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulse = minPulse; // Set the motor position value to the minimum
beginSerial(9600);
}
void loop() {
// read analog input from 'analogPin'
analogValue = analogRead(analogPin);
// calculate the input relative to the input range and angle range
myVar = (analogValue * 180)/1023;
// change the analog reading to the wanted range (between 500 to 2500)
//myVar = minPulse + (analogValue * 2);
turnServo( myVar );
// turn servo to the 50 degrees mark
turnServo(50);
delay(500);
turnServo(5);
delay(500);
turnServo(150);
delay(500);
turnServo(5);
delay(500);
turnServo(20);
delay(500);
turnServo(90);
delay(500);
}
// brings servo motor to the wanted angle (between 0 to 180 degrees)
void turnServo(int angle) {
int i;
// this loop is done in order to turn the servo motor to the wanted angle
for( i=1; i;)
pulse = (i*2500)/180;
pulse += 500+((2000/180)*i);
pulsout( servoPin, pulse);
}
void pulsout( int servoPin, int pulse) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
delay(20); // 20 millisecond delay is needed between pulses
}
// newline function -> prints out new line (\n) as well as a carriage return (\c);
void newline() {
printNewline();
printByte(13);
}