MP

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); //D9
00004 
00005 PwmOut PWM2(PA_11); //D10
00006 
00007 PwmOut PWM3(PF_0); //D7
00008 
00009 PwmOut PWM4(PB_1); //D6
00010 
00011  
00012 float map (int x, int in_min,int  in_max, float out_min, float out_max)
00013 {
00014   return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
00015 }
00016  
00017 
00018 void Pince_Gauche(int a)
00019 {//50avant 0 arriere
00020 PWM1.period_ms(20); 
00021 PWM1.write(map (a,0,180,0.028f,0.12f));   
00022 } 
00023  
00024 void Pince_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_Droite(40);
00032     Pince_Gauche(5);
00033     }
00034 void fermeture()
00035 {
00036     Pince_Droite(10);
00037     Pince_Gauche(45);
00038     }
00039 
00040  
00041 void GAUCHE_MONTE_CHARGE(int a)
00042 {//0 avant 50 arriere
00043 PWM4.period_ms(20); 
00044 PWM4.write(map (a,0,180,0.028f,0.12f));   
00045 }
00046 void DROITE_MONTE_CHARGE(int a)
00047 {// 40 ouverture 0 fermeture
00048 PWM3.period_ms(20); 
00049 PWM3.write(map (a,0,180,0.028f,0.12f));   
00050 }
00051 
00052 void Pince_Haut()
00053 {
00054 GAUCHE_MONTE_CHARGE(40);
00055 DROITE_MONTE_CHARGE(40);
00056 }
00057 void Pince_Bas()
00058 {
00059 GAUCHE_MONTE_CHARGE(0);
00060 DROITE_MONTE_CHARGE(0);
00061 }
00062 
00063 
00064 int main() 
00065 {
00066  
00067  
00068     while(1) {
00069 Pince_Bas();
00070 wait(1);
00071 ouverture();
00072 wait(1); 
00073 fermeture(); 
00074 wait(1); 
00075 Pince_Haut();
00076 wait(1); 
00077 
00078  }
00079 }
00080