Motor

Another project was a brief excursion into the world of electric motors. In this particular (short!) project, we were tasked with creating something simple with a motor, stepper, or servo.

I had originally wanted to do something through Flash with the servo, but found that to be too difficult for the scope of the project. The main reason for this is that Flash is rather atrocious when it comes to controlling time precisely. The PWM calls to the servo motor required mili- and micro-second accuracy, something Flash just doesn’t have.

As a substitute, I scaled things back to just using that cute volume slider from the Blink project to control the rotation of the servo: all the way left, all the way right, and everywhere in between.

Motor

Motor Code

int ana;
float forMath;
int servoPin = 7;
int pulseWidth = 700;

void setup(){
pinMode(servoPin, OUTPUT);
Serial.begin(9600);
ana = 0;
}

void loop(){
ana = analogRead(0); // a reading from the slider
forMath = ana; // stored as a float
ana = (forMath/660*180); // returned to an int
Serial.println(ana); // printed
servoPulse(servoPin, ana); // sent to the servo
}

void servoPulse(int servoPin, int myAngle) {
pulseWidth = (myAngle * 9) + 700; // converts angle to microseconds
digitalWrite(servoPin, HIGH); // set servo high
delayMicroseconds(pulseWidth); // wait a very small amount
digitalWrite(servoPin, LOW); // set servo low
//Serial.print(“pulseWidth: “); Serial.println(pulseWidth);
delay(20); // refresh cycle of typical servos (20 ms)
}

5 Comments »

  1. Hornis and Hooveis said,

    March 16, 2012 @ 12:11 pm

    Admin blog.jp-design.net
    Adv.ag. “Hornis and Hooveis” want buy baner space on thise page.
    From at 50$.
    Call: +881835211209 +299588001 +882322000030

  2. Www.Kit.camp said,

    January 29, 2021 @ 8:03 am

    http://Www.Kit.camp...

    Joe Pietruch's Blog…

  3. free Bitcoin miner app review said,

    May 21, 2021 @ 1:43 pm

    free Bitcoin miner app review…

    Joe Pietruch's Blog…

  4. Football Betting said,

    August 3, 2021 @ 10:07 am

    Football Betting…

    Joe Pietruch's Blog…

  5. seo said,

    January 25, 2022 @ 10:20 am

    seo…

    Joe Pietruch's Blog…

RSS feed for comments on this post · TrackBack URI

Leave a Comment