Version final modification amplitude et période d'un sinus

Dependencies:   mbed ihm_L476_full

Files at this revision

API Documentation at this revision

Comitter:
grimwald
Date:
Sun May 30 14:16:48 2021 +0000
Parent:
0:b30577700066
Commit message:
VF;

Changed in this revision

ihm_L476_full.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b30577700066 -r 4fb9517beb4d ihm_L476_full.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ihm_L476_full.lib	Sun May 30 14:16:48 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/IUT-CACHAN-GE1/code/ihm_L476_full/#e9777c284d79
diff -r b30577700066 -r 4fb9517beb4d main.cpp
--- a/main.cpp	Wed May 06 16:12:07 2020 +0000
+++ b/main.cpp	Sun May 30 14:16:48 2021 +0000
@@ -1,21 +1,97 @@
 #include "mbed.h"
+#include "ihm_L476.h"
+#include"math.h"
+#define PI 3.14
+//initialisation des objets
+Serial pc(SERIAL_TX, SERIAL_RX);//permet la communication avec le terminal en liason serie
+LCD_DISCO_L476VG lcd;
 
-Serial pc(SERIAL_TX, SERIAL_RX);//permet la communication avec le terminal en liason seri
-DigitalOut led(LED1);
+InterruptIn Up(PA_3,PullDown);
+InterruptIn Down(PA_5,PullDown);
+InterruptIn Right(PA_2,PullDown);
+InterruptIn Left(PA_1,PullDown);
+//initialisation des variables
+int t=0;
+double PER=1000;
+double cadence=0.01;
+double y1;
+double y2;
+double moyenne=0;
+double somme=0;
+double amplitude=2000;
 
+bool flag=false;
+bool flag2=false;
+uint8_t tab[50];
+uint8_t tab2[50];
+Ticker tick_cadence,tick_moyenne;
+
+void interrupt(void);
+void val_moy(void);
+void up(void);
+void down(void);
+void right(void);
+void left(void);
 int main()
 {
-    pc.printf("Press '1' to turn LED1 ON, '0' to turn it OFF\n");// va print sur le terminal
+    Up.rise(&up);
+    Down.rise(&down);
+    Right.rise(&right);
+    Left.rise(&left);
+    
+    pc.baud(115200);
+    //on attache le ticker a la fonction
+    tick_cadence.attach(&interrupt, 0.01);
+    tick_moyenne.attach(&val_moy, 1);
     while(1) {
-        char c;
-        pc.printf("Tapez 1 pour allumer 0 pour eteindre:");
-        pc.scanf("%c",&c);// va nous permettre d'entrer  l'état 1 ou 0 (on/off) depuis le terminal.
-        
-        if (c == '0') {
-            led = 0; // OFF
+        y1= (amplitude/1000)*sin(2.0*PI*(1.0/(PER/1000))*(t*cadence));
+        y2= 2* fabs(y1);
+        somme=somme+y2;
+        if(flag2) {
+            sprintf((char*)tab2,"%lf",amplitude);
+            lcd.DisplayString(tab2);
+            lcd.Clear();
+            flag2=false;
         }
-        if (c == '1') {
-            led = 1; // ON
+        if(flag) {
+            sprintf((char*)tab2,"%lf",PER);
+            lcd.DisplayString(tab2);
+            lcd.Clear();
+            flag=false;
         }
+        sprintf((char*)tab,"%lf",moyenne);
+        lcd.DisplayString(tab);
+        pc.printf("$%lf %lf %lf;",y1,y2,moyenne);
     }
 }
+//fonction periodique qui incrémente t
+void interrupt(void)
+{
+    t++;
+}
+//fonction periodique qui met a true le flag toute les 1 sec
+void val_moy(void)
+{
+    moyenne=somme/256;
+    somme=0;
+}
+void up(void)
+{
+    amplitude+=100;
+    flag2=true;
+}
+void down(void)
+{
+    amplitude-=100;
+    flag2=true;
+}
+void right(void)
+{
+    PER+=100;
+    flag=true;
+}
+void left(void)
+{
+    PER-=100;
+    flag=true;
+}
\ No newline at end of file