I connected a flex sensor instead of a pot. When I bent a flex sensor, a servo changed. Actually I did this lab with Chris and David because we are in the same group. The voices in this video are from them .
Wednesday, October 3, 2007
Lab_04 | The servo follows the pot!
After I programmed the microcontroller, I could make the servo move.
Lab_04 | Programming the microcontroller
I copied and pasted this code from the lab page
but I didn't understand this code very well.
I think I need to study programming arduino more..
int servoPin = 2;
int minPulse = 500;
int maxPulse = 2500;
int pulse = 0;
long lastPulse = 0;
int refreshTime = 20;
int analogValue = 0;
int analogPin = 0;
void setup() {
pinMode(servoPin, OUTPUT);
pulse = minPulse;
Serial.begin(9600);
}
void loop() {
analogValue = analogRead(analogPin);
pulse = (analogValue * 19) / 10 + minPulse;
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH);
delayMicroseconds(pulse);
digitalWrite(servoPin, LOW);
lastPulse = millis();
}
}
Lab_04 | Connect an anolog input and a servo
Subscribe to:
Posts (Atom)