Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:656a20620e62
- Parent:
- 0:f07bc5dab40d
- Child:
- 3:e750507bf900
diff -r b932f9e6d701 -r 656a20620e62 main.cpp
--- a/main.cpp Wed Feb 20 20:50:33 2019 +0000
+++ b/main.cpp Tue Feb 26 14:17:36 2019 +0000
@@ -1,5 +1,6 @@
#include "mbed.h"
#include <PwmIn.h>
+#include <stdio.h>
DigitalIn mybutton(USER_BUTTON);
DigitalOut trig(PA_10);
@@ -7,39 +8,91 @@
PwmIn LidarI(PB_3);
float mes = 0;
-int arret=0,n=0,i=0;
+int arret = 0, n = 0, i = 0;
float boucleM(){
wait_ms(10);
- mes = LidarI.pulsewidth();
+ mes = LidarI.pulsewidth() / 10;
if(mes!=0){
- pc.printf("Mesure : %1.2f\n",mes/10);
+ pc.printf("Mesure : %f\n",mes);
} else pc.printf("Erreur : valeur nulles.\n");
arret = !mybutton.read();
- return (mes/10);
+ return (mes);
}
+
+
+void rotation(float angle){
+
+
+ }
int main() {
+ float aireTotale = 0, aireTriangle = 0, angle;
+
+
+
pc.printf("\nLancement du programme...\n");
pc.printf("Combien de mesures allez-vous prendre ?\n");
pc.scanf("%d",&n);
pc.printf("%d\n\n",n);
float tabM[n];
+ angle = 360 / n; // Angle de chaque rotation du moteur
+
trig = 1;
trig=0;
wait_us(500);
+
+ tabM[i]=boucleM();
+ i++;
while(i<n){
tabM[i]=boucleM();
i++;
+ //Fonction rotation moteur rotation(float angle);
+ wait(2);
+
+ aireTriangle = (tabM[i - 1] * tabM[i] * sin(angle) ) / 2;
+ aireTotale += aireTriangle;
}
i=0;
while(i<n){
- pc.printf("M(%d):[%f]\n",i,tabM[i]);
+ pc.printf("M(%d):[%f]\n",i ,tabM[i]);
i=i++;
}
+
+ pc.printf("\n Aire total : %f \n", aireTotale);
pc.printf("Arret du programme...");
sleep();
}
+
+
+
+
+
+
+
+ /* DEUXIEME VERSION A METTRE DANS MAIN
+ passe dans la tableau et calcule l'aire une fois que les mesures sont prises
+
+
+ i = 1;
+ while (i < n){
+
+ aireTriangle = (tabM[i - 1] * tabM[i] * sin(angle) ) / 2;
+ aireTotale += aireTriangle;
+ i++;
+ }
+
+
+
+ */
+
+
+
+
+
+
+
+
\ No newline at end of file