Yay!

Dependencies:   mbed

Committer:
fkgjh
Date:
Thu Oct 22 12:01:15 2015 +0000
Revision:
0:aff2ce7d4765
Servomotor - sakte opp, fort ned;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fkgjh 0:aff2ce7d4765 1 #include "mbed.h"
fkgjh 0:aff2ce7d4765 2 #include "PwmOut.h"
fkgjh 0:aff2ce7d4765 3
fkgjh 0:aff2ce7d4765 4 PwmOut servoMotor(PA_7);
fkgjh 0:aff2ce7d4765 5
fkgjh 0:aff2ce7d4765 6 int main()
fkgjh 0:aff2ce7d4765 7 {
fkgjh 0:aff2ce7d4765 8 servoMotor.period(.01);
fkgjh 0:aff2ce7d4765 9 while(true)
fkgjh 0:aff2ce7d4765 10 {
fkgjh 0:aff2ce7d4765 11 int i;
fkgjh 0:aff2ce7d4765 12
fkgjh 0:aff2ce7d4765 13 for(i=1000;i<=2000;i++)
fkgjh 0:aff2ce7d4765 14 {
fkgjh 0:aff2ce7d4765 15 servoMotor=1;
fkgjh 0:aff2ce7d4765 16 servoMotor.pulsewidth_us(1000);
fkgjh 0:aff2ce7d4765 17 wait(0.2);
fkgjh 0:aff2ce7d4765 18 servoMotor.pulsewidth_us(1050);
fkgjh 0:aff2ce7d4765 19 wait(0.2);
fkgjh 0:aff2ce7d4765 20 servoMotor.pulsewidth_us(1100);
fkgjh 0:aff2ce7d4765 21 wait(0.2);
fkgjh 0:aff2ce7d4765 22 servoMotor.pulsewidth_us(1150);
fkgjh 0:aff2ce7d4765 23 wait(0.2);
fkgjh 0:aff2ce7d4765 24 servoMotor.pulsewidth_us(1200);
fkgjh 0:aff2ce7d4765 25 wait(0.2);
fkgjh 0:aff2ce7d4765 26 servoMotor.pulsewidth_us(1250);
fkgjh 0:aff2ce7d4765 27 wait(0.2);
fkgjh 0:aff2ce7d4765 28 servoMotor.pulsewidth_us(1300);
fkgjh 0:aff2ce7d4765 29 wait(0.2);
fkgjh 0:aff2ce7d4765 30 servoMotor.pulsewidth_us(1350);
fkgjh 0:aff2ce7d4765 31 wait(0.2);
fkgjh 0:aff2ce7d4765 32 servoMotor.pulsewidth_us(1400);
fkgjh 0:aff2ce7d4765 33 wait(0.2);
fkgjh 0:aff2ce7d4765 34 servoMotor.pulsewidth_us(1450);
fkgjh 0:aff2ce7d4765 35 wait(0.2);
fkgjh 0:aff2ce7d4765 36 servoMotor.pulsewidth_us(1500);
fkgjh 0:aff2ce7d4765 37 wait(0.2);
fkgjh 0:aff2ce7d4765 38 servoMotor.pulsewidth_us(1550);
fkgjh 0:aff2ce7d4765 39 wait(0.2);
fkgjh 0:aff2ce7d4765 40 servoMotor.pulsewidth_us(1600);
fkgjh 0:aff2ce7d4765 41 wait(0.2);
fkgjh 0:aff2ce7d4765 42 servoMotor.pulsewidth_us(1650);
fkgjh 0:aff2ce7d4765 43 wait(0.2);
fkgjh 0:aff2ce7d4765 44 servoMotor.pulsewidth_us(1700);
fkgjh 0:aff2ce7d4765 45 wait(0.2);
fkgjh 0:aff2ce7d4765 46 servoMotor.pulsewidth_us(1750);
fkgjh 0:aff2ce7d4765 47 wait(0.2);
fkgjh 0:aff2ce7d4765 48 servoMotor.pulsewidth_us(1800);
fkgjh 0:aff2ce7d4765 49 wait(0.2);
fkgjh 0:aff2ce7d4765 50 servoMotor.pulsewidth_us(1850);
fkgjh 0:aff2ce7d4765 51 wait(0.2);
fkgjh 0:aff2ce7d4765 52 servoMotor.pulsewidth_us(1900);
fkgjh 0:aff2ce7d4765 53 wait(0.2);
fkgjh 0:aff2ce7d4765 54 servoMotor.pulsewidth_us(1950);
fkgjh 0:aff2ce7d4765 55 wait(0.2);
fkgjh 0:aff2ce7d4765 56 servoMotor.pulsewidth_us(2000);
fkgjh 0:aff2ce7d4765 57 }
fkgjh 0:aff2ce7d4765 58
fkgjh 0:aff2ce7d4765 59 wait(0.2);
fkgjh 0:aff2ce7d4765 60 for(i=2000;i>=1000;i--)
fkgjh 0:aff2ce7d4765 61 {
fkgjh 0:aff2ce7d4765 62 servoMotor=2;
fkgjh 0:aff2ce7d4765 63 servoMotor.pulsewidth_us(2000);
fkgjh 0:aff2ce7d4765 64
fkgjh 0:aff2ce7d4765 65 }
fkgjh 0:aff2ce7d4765 66 wait(0.2);
fkgjh 0:aff2ce7d4765 67 }
fkgjh 0:aff2ce7d4765 68 }