wassim boumaiza / Mbed 2 deprecated SPICommSTM32f4

Dependencies:   mbed

Fork of SPICommSTM32f4 by Khemiri Mahrane

Files at this revision

API Documentation at this revision

Comitter:
wassim94
Date:
Tue Feb 23 17:11:28 2016 +0000
Parent:
0:ce4f87a989a6
Commit message:
spi

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Feb 09 18:16:28 2016 +0000
+++ b/main.cpp	Tue Feb 23 17:11:28 2016 +0000
@@ -1,24 +1,93 @@
 #include "mbed.h"
 
 SPISlave SPINUCLEO(PA_7,PA_6,PA_5,PA_4);
-DigitalOut myled(LED1);
+//DigitalOut myled(LED1);
+
+PwmOut PWM1(PA_8);
+//TIM1_CH4  //Pince bas gauche
+PwmOut PWM2(PA_11);
+//TIM16_CH1
+PwmOut PWM3(PA_12);// Pince Glissement Gauche
+//TIM3_CH1
+PwmOut PWM4(PB_0);//Pince Glissement droite
+//TIM3_CH4
+PwmOut PWM5(PB_7);
+//TIM17_CH1N
+PwmOut PWM6(PB_6);
+//TIM3_CH4,
+PwmOut PWM7(PB_1);
+//TIM3_CH3
+PwmOut PWM8(PF_0); //pince bas droite
+
+float map (int x, int in_min,int  in_max, float out_min, float out_max)
+{
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+void Pince_Bas_Gauche(int a)
+{// 40 ouverture 0 fermeture
+PWM2.period_ms(20); 
+PWM2.write(map (a,0,180,0.028f,0.12f));   
+}
+
+void Pince_Bas_Droite(int a)
+{// 0 ouverture 40 fermeture
+PWM8.period_ms(20); 
+PWM8.write(map (a,0,180,0.028f,0.12f));   
+}
+void ouverture()
+{
+    Pince_Bas_Droite(0);
+    Pince_Bas_Gauche(40);
+    }
+void fermeture()
+{
+    Pince_Bas_Droite(40);
+    Pince_Bas_Gauche(0);
+    }
+void Pince_Glissement_Gauche(int a)
+{//50avant 0 arriere
+PWM3.period_ms(20); 
+PWM3.write(map (a,0,180,0.028f,0.12f));   
+}
+
+void Pince_Glissement_Droit(int a)
+{//0avant 50 arriere
+PWM4.period_ms(20); 
+PWM4.write(map (a,0,180,0.028f,0.12f));   
+}
+void Pince_arriere()
+{
+Pince_Glissement_Droit(0);
+Pince_Glissement_Gauche(50);
+}
+void Pince_avant()
+{
+Pince_Glissement_Droit(55);
+Pince_Glissement_Gauche(0);
+}
+
 int main() {
- int a=0;
- myled = 0;
+int a=0;
 SPINUCLEO.frequency(21000000);  
 SPINUCLEO.reply(0x00);
 
+ouverture();
+
 while (1)
 {
 if (SPINUCLEO.receive())
 {
 a=SPINUCLEO.read();
-SPINUCLEO.reply(a);
- myled = 1;
-wait(2);  
-myled = 0;
-wait(2); 
-}
+if(a==0x0A)
+{
+ ouverture();
+ wait(2);
+ fermeture();
+ wait(2);
+ SPINUCLEO.reply(0x0B);
+ 
+}}
 
 }