ServoProg

Dependencies:   mbed

Committer:
Mahran
Date:
Tue Feb 09 13:08:49 2016 +0000
Revision:
0:bb0da30d43f4
Child:
1:c56c4fb5cb59
PWMSERVO;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mahran 0:bb0da30d43f4 1 #include "mbed.h"
Mahran 0:bb0da30d43f4 2 //TIM1_CH1
Mahran 0:bb0da30d43f4 3 PwmOut PWM1(PA_8);
Mahran 0:bb0da30d43f4 4 //TIM1_CH4
Mahran 0:bb0da30d43f4 5 PwmOut PWM2(PA_11);
Mahran 0:bb0da30d43f4 6 //TIM16_CH1
Mahran 0:bb0da30d43f4 7 PwmOut PWM3(PA_12);
Mahran 0:bb0da30d43f4 8 //TIM3_CH1
Mahran 0:bb0da30d43f4 9 PwmOut PWM4(PB_0);
Mahran 0:bb0da30d43f4 10 //TIM3_CH4
Mahran 0:bb0da30d43f4 11 PwmOut PWM5(PB_7);
Mahran 0:bb0da30d43f4 12 //TIM17_CH1N
Mahran 0:bb0da30d43f4 13 PwmOut PWM6(PB_6);
Mahran 0:bb0da30d43f4 14 //TIM3_CH4,
Mahran 0:bb0da30d43f4 15 PwmOut PWM7(PB_1);
Mahran 0:bb0da30d43f4 16 //TIM3_CH3
Mahran 0:bb0da30d43f4 17 PwmOut PWM8(PB_0);
Mahran 0:bb0da30d43f4 18
Mahran 0:bb0da30d43f4 19 float map (int x, int in_min,int in_max, float out_min, float out_max)
Mahran 0:bb0da30d43f4 20 {
Mahran 0:bb0da30d43f4 21 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
Mahran 0:bb0da30d43f4 22 }
Mahran 0:bb0da30d43f4 23
Mahran 0:bb0da30d43f4 24 void Pince_Bas_Gauche(int a)
Mahran 0:bb0da30d43f4 25 {
Mahran 0:bb0da30d43f4 26 PWM1.period_ms(20);
Mahran 0:bb0da30d43f4 27 PWM1.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 28 }
Mahran 0:bb0da30d43f4 29
Mahran 0:bb0da30d43f4 30 void Pince_Bas_Droite(int a)
Mahran 0:bb0da30d43f4 31 {
Mahran 0:bb0da30d43f4 32 PWM2.period_ms(20);
Mahran 0:bb0da30d43f4 33 PWM2.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 34 }
Mahran 0:bb0da30d43f4 35
Mahran 0:bb0da30d43f4 36 void Pince_Glissement_Gauche(int a)
Mahran 0:bb0da30d43f4 37 {
Mahran 0:bb0da30d43f4 38 PWM3.period_ms(20);
Mahran 0:bb0da30d43f4 39 PWM3.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 40 }
Mahran 0:bb0da30d43f4 41
Mahran 0:bb0da30d43f4 42 void Pince_Glissement_Droit(int a)
Mahran 0:bb0da30d43f4 43 {
Mahran 0:bb0da30d43f4 44 PWM4.period_ms(20);
Mahran 0:bb0da30d43f4 45 PWM4.write(map (a,0,180,0.028f,0.12f));
Mahran 0:bb0da30d43f4 46 }
Mahran 0:bb0da30d43f4 47
Mahran 0:bb0da30d43f4 48 int main()
Mahran 0:bb0da30d43f4 49 {
Mahran 0:bb0da30d43f4 50
Mahran 0:bb0da30d43f4 51 while(1) {
Mahran 0:bb0da30d43f4 52
Mahran 0:bb0da30d43f4 53 }
Mahran 0:bb0da30d43f4 54 }