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();
}
}
Wednesday, October 3, 2007
Lab_04 | Programming the microcontroller
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment