Sunday, October 4, 2009

heliostropic organic: pic and code

This is the heliotropic organic (without fabric), all circuits are masked inside
courtesy: John Marshall

The coding is shared here and explained by previous blogs:

#include // include the servo library

Servo servoMotor0; // creates an instance of the servo object to control a servo
Servo servoMotor1;
Servo servoMotor2;
int analogPin0 = 0; // the analog pin that the sensor is on
int analogPin1 = 1;
int analogPin2 = 2;
int analogValue0 = 0; // the value returned from the analog sensor
int analogValue1 = 0;
int analogValue2 = 0;
int servoPin0 = 2; // Control pin for servo motor, may only be pin 9 or 10
int servoPin1= 3;
int servoPin2 = 4;
void setup() {
servoMotor0.attach(servoPin0); // attaches the servo on pin 2 to the servo object
servoMotor1.attach(servoPin1);
servoMotor2.attach(servoPin2);
}
void loop()
{
analogValue0 = analogRead(analogPin0); // read the analog input (value between 0 and 1023)
analogValue1 = analogRead(analogPin1);
analogValue2 = analogRead(analogPin2);
analogValue0 = map(analogValue0,50, 1023, 0, 360); // map the analog value (0 - 1023) to the angle of the servo (0 - 179)
analogValue1 = map(analogValue1, 50, 1023, 0, 360);
analogValue2 = map(analogValue2, 50, 1023, 0, 360);
servoMotor0.write(analogValue0); // write the new mapped analog value to set the position of the servo
servoMotor1.write(analogValue1);
servoMotor2.write(analogValue2);
delay(500); // waits for the servo to get there
}

No comments:

Post a Comment