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

Dependencies:   mbed ihm_L476_full

Committer:
grimwald
Date:
Sun May 30 14:16:48 2021 +0000
Revision:
1:4fb9517beb4d
Parent:
0:b30577700066
VF;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grimwald 0:b30577700066 1 #include "mbed.h"
grimwald 1:4fb9517beb4d 2 #include "ihm_L476.h"
grimwald 1:4fb9517beb4d 3 #include"math.h"
grimwald 1:4fb9517beb4d 4 #define PI 3.14
grimwald 1:4fb9517beb4d 5 //initialisation des objets
grimwald 1:4fb9517beb4d 6 Serial pc(SERIAL_TX, SERIAL_RX);//permet la communication avec le terminal en liason serie
grimwald 1:4fb9517beb4d 7 LCD_DISCO_L476VG lcd;
grimwald 0:b30577700066 8
grimwald 1:4fb9517beb4d 9 InterruptIn Up(PA_3,PullDown);
grimwald 1:4fb9517beb4d 10 InterruptIn Down(PA_5,PullDown);
grimwald 1:4fb9517beb4d 11 InterruptIn Right(PA_2,PullDown);
grimwald 1:4fb9517beb4d 12 InterruptIn Left(PA_1,PullDown);
grimwald 1:4fb9517beb4d 13 //initialisation des variables
grimwald 1:4fb9517beb4d 14 int t=0;
grimwald 1:4fb9517beb4d 15 double PER=1000;
grimwald 1:4fb9517beb4d 16 double cadence=0.01;
grimwald 1:4fb9517beb4d 17 double y1;
grimwald 1:4fb9517beb4d 18 double y2;
grimwald 1:4fb9517beb4d 19 double moyenne=0;
grimwald 1:4fb9517beb4d 20 double somme=0;
grimwald 1:4fb9517beb4d 21 double amplitude=2000;
grimwald 0:b30577700066 22
grimwald 1:4fb9517beb4d 23 bool flag=false;
grimwald 1:4fb9517beb4d 24 bool flag2=false;
grimwald 1:4fb9517beb4d 25 uint8_t tab[50];
grimwald 1:4fb9517beb4d 26 uint8_t tab2[50];
grimwald 1:4fb9517beb4d 27 Ticker tick_cadence,tick_moyenne;
grimwald 1:4fb9517beb4d 28
grimwald 1:4fb9517beb4d 29 void interrupt(void);
grimwald 1:4fb9517beb4d 30 void val_moy(void);
grimwald 1:4fb9517beb4d 31 void up(void);
grimwald 1:4fb9517beb4d 32 void down(void);
grimwald 1:4fb9517beb4d 33 void right(void);
grimwald 1:4fb9517beb4d 34 void left(void);
grimwald 0:b30577700066 35 int main()
grimwald 0:b30577700066 36 {
grimwald 1:4fb9517beb4d 37 Up.rise(&up);
grimwald 1:4fb9517beb4d 38 Down.rise(&down);
grimwald 1:4fb9517beb4d 39 Right.rise(&right);
grimwald 1:4fb9517beb4d 40 Left.rise(&left);
grimwald 1:4fb9517beb4d 41
grimwald 1:4fb9517beb4d 42 pc.baud(115200);
grimwald 1:4fb9517beb4d 43 //on attache le ticker a la fonction
grimwald 1:4fb9517beb4d 44 tick_cadence.attach(&interrupt, 0.01);
grimwald 1:4fb9517beb4d 45 tick_moyenne.attach(&val_moy, 1);
grimwald 0:b30577700066 46 while(1) {
grimwald 1:4fb9517beb4d 47 y1= (amplitude/1000)*sin(2.0*PI*(1.0/(PER/1000))*(t*cadence));
grimwald 1:4fb9517beb4d 48 y2= 2* fabs(y1);
grimwald 1:4fb9517beb4d 49 somme=somme+y2;
grimwald 1:4fb9517beb4d 50 if(flag2) {
grimwald 1:4fb9517beb4d 51 sprintf((char*)tab2,"%lf",amplitude);
grimwald 1:4fb9517beb4d 52 lcd.DisplayString(tab2);
grimwald 1:4fb9517beb4d 53 lcd.Clear();
grimwald 1:4fb9517beb4d 54 flag2=false;
grimwald 0:b30577700066 55 }
grimwald 1:4fb9517beb4d 56 if(flag) {
grimwald 1:4fb9517beb4d 57 sprintf((char*)tab2,"%lf",PER);
grimwald 1:4fb9517beb4d 58 lcd.DisplayString(tab2);
grimwald 1:4fb9517beb4d 59 lcd.Clear();
grimwald 1:4fb9517beb4d 60 flag=false;
grimwald 0:b30577700066 61 }
grimwald 1:4fb9517beb4d 62 sprintf((char*)tab,"%lf",moyenne);
grimwald 1:4fb9517beb4d 63 lcd.DisplayString(tab);
grimwald 1:4fb9517beb4d 64 pc.printf("$%lf %lf %lf;",y1,y2,moyenne);
grimwald 0:b30577700066 65 }
grimwald 0:b30577700066 66 }
grimwald 1:4fb9517beb4d 67 //fonction periodique qui incrémente t
grimwald 1:4fb9517beb4d 68 void interrupt(void)
grimwald 1:4fb9517beb4d 69 {
grimwald 1:4fb9517beb4d 70 t++;
grimwald 1:4fb9517beb4d 71 }
grimwald 1:4fb9517beb4d 72 //fonction periodique qui met a true le flag toute les 1 sec
grimwald 1:4fb9517beb4d 73 void val_moy(void)
grimwald 1:4fb9517beb4d 74 {
grimwald 1:4fb9517beb4d 75 moyenne=somme/256;
grimwald 1:4fb9517beb4d 76 somme=0;
grimwald 1:4fb9517beb4d 77 }
grimwald 1:4fb9517beb4d 78 void up(void)
grimwald 1:4fb9517beb4d 79 {
grimwald 1:4fb9517beb4d 80 amplitude+=100;
grimwald 1:4fb9517beb4d 81 flag2=true;
grimwald 1:4fb9517beb4d 82 }
grimwald 1:4fb9517beb4d 83 void down(void)
grimwald 1:4fb9517beb4d 84 {
grimwald 1:4fb9517beb4d 85 amplitude-=100;
grimwald 1:4fb9517beb4d 86 flag2=true;
grimwald 1:4fb9517beb4d 87 }
grimwald 1:4fb9517beb4d 88 void right(void)
grimwald 1:4fb9517beb4d 89 {
grimwald 1:4fb9517beb4d 90 PER+=100;
grimwald 1:4fb9517beb4d 91 flag=true;
grimwald 1:4fb9517beb4d 92 }
grimwald 1:4fb9517beb4d 93 void left(void)
grimwald 1:4fb9517beb4d 94 {
grimwald 1:4fb9517beb4d 95 PER-=100;
grimwald 1:4fb9517beb4d 96 flag=true;
grimwald 1:4fb9517beb4d 97 }