servo

Dependencies:   mbed

Fork of Nucleo_PWM by Khemiri Mahrane

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 //TIM1_CH1  //Pince Bas gauche
00003 PwmOut PWM1(PA_8);
00004 //TIM1_CH4  //Pince bas droite
00005 PwmOut PWM2(PA_9);
00006 //TIM16_CH1
00007 PwmOut PWM3(PB_4);// Pince Glissement Gauche
00008 //TIM3_CH1
00009 PwmOut PWM4(PB_10);//Pince Glissement droite
00010 //TIM3_CH4
00011 
00012 
00013 float map (int x, int in_min,int  in_max, float out_min, float out_max)
00014 {
00015   return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
00016 }
00017 
00018 void Pince_Bas_Gauche(int a)
00019 {// 40 ouverture 0 fermeture
00020 PWM1.period_ms(20); 
00021 PWM1.write(map (a,0,180,0.028f,0.12f));   
00022 }
00023 
00024 void Pince_Bas_Droite(int a)
00025 {// 0 ouverture 40 fermeture
00026 PWM2.period_ms(20); 
00027 PWM2.write(map (a,0,180,0.028f,0.12f));   
00028 }
00029 void ouverture()
00030 {
00031 Pince_Bas_Gauche(80);
00032 Pince_Bas_Droite(10);
00033     }
00034 void fermeture()
00035 {
00036     Pince_Bas_Gauche(30);
00037     Pince_Bas_Droite(60);
00038 }
00039 void Pince_Glissement_Gauche(int a)
00040 {//50avant 0 arriere
00041 PWM3.period_ms(20); 
00042 PWM3.write(map (a,0,180,0.028f,0.12f));   
00043 }
00044 
00045 void Pince_Glissement_Droit(int a)
00046 {//0avant 50 arriere
00047 PWM4.period_ms(20); 
00048 PWM4.write(map (a,0,180,0.028f,0.12f));   
00049 }
00050 void Pince_arriere()
00051 {
00052 Pince_Glissement_Droit(0);
00053 Pince_Glissement_Gauche(50);
00054 }
00055 void Pince_avant()
00056 {
00057 Pince_Glissement_Droit(50);
00058 Pince_Glissement_Gauche(0);
00059 }
00060 int main() 
00061 {
00062 
00063 
00064 
00065 while(1){
00066     Pince_Glissement_Gauche(90);
00067 Pince_Glissement_Droit(90);
00068 
00069     wait(1);
00070 Pince_Glissement_Gauche(0);
00071 Pince_Glissement_Droit(0);
00072     wait(1);
00073     }
00074 }