Devoir Maison d'ER1 Exercice n°1

Dependencies:   mbed tsi_sensor

Committer:
vermaelen
Date:
Fri Oct 19 09:39:19 2018 +0000
Revision:
1:a51043da3ab9
Parent:
0:51f7a12253d1
version 1.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vermaelen 0:51f7a12253d1 1 #include "mbed.h"
vermaelen 0:51f7a12253d1 2 #include "tsi_sensor.h"
vermaelen 0:51f7a12253d1 3 #include "lib.h"
vermaelen 0:51f7a12253d1 4
vermaelen 0:51f7a12253d1 5 PwmOut led(LED_GREEN); //déclaration de la sortie PWM
vermaelen 0:51f7a12253d1 6
vermaelen 0:51f7a12253d1 7 int main(void) {
vermaelen 0:51f7a12253d1 8 float val; //déclaration des variables
vermaelen 0:51f7a12253d1 9 float t_etat_haut;
vermaelen 0:51f7a12253d1 10 led.period(0.001); //periode de la PWM = 0.001 s = 1 ms
vermaelen 0:51f7a12253d1 11 while (1) { //boucle infinie
vermaelen 0:51f7a12253d1 12 val=lire_slider(); //lecture du slider (valeur comprise entre 0 et 1)
vermaelen 1:a51043da3ab9 13 printf("%f\n\r",val); //ecriture de val sur la liaison série (console TeraTerm)
vermaelen 0:51f7a12253d1 14 t_etat_haut=val*0.001; //on fixe la durée du temps haut en fonction de val
vermaelen 0:51f7a12253d1 15 led.pulsewidth(t_etat_haut);//écriture de l'état haut
vermaelen 0:51f7a12253d1 16 wait(0.1); //attente de 100 ms
vermaelen 0:51f7a12253d1 17 }
vermaelen 0:51f7a12253d1 18 }