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.
main.cpp
- Committer:
- karteck
- Date:
- 2019-02-26
- Revision:
- 2:656a20620e62
- Parent:
- 0:f07bc5dab40d
- Child:
- 3:e750507bf900
File content as of revision 2:656a20620e62:
#include "mbed.h"
#include <PwmIn.h>
#include <stdio.h>
DigitalIn mybutton(USER_BUTTON);
DigitalOut trig(PA_10);
Serial pc(USBTX,USBRX);
PwmIn LidarI(PB_3);
float mes = 0;
int arret = 0, n = 0, i = 0;
float boucleM(){
wait_ms(10);
mes = LidarI.pulsewidth() / 10;
if(mes!=0){
pc.printf("Mesure : %f\n",mes);
} else pc.printf("Erreur : valeur nulles.\n");
arret = !mybutton.read();
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]);
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++;
}
*/