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.
Dependencies: mbed
Revision 1:5ced6fbeaf18, committed 2017-04-01
- Comitter:
- marc1119
- Date:
- Sat Apr 01 02:11:04 2017 +0000
- Parent:
- 0:aba7c91f4213
- Child:
- 2:92e518f9238d
- Commit message:
- Cr?er le code pour l'app
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Apr 01 01:45:20 2017 +0000 +++ b/main.cpp Sat Apr 01 02:11:04 2017 +0000 @@ -1,12 +1,29 @@ #include "mbed.h" +#include <math.h> -DigitalOut myled(LED1); +//Coefficients pour la régression. +#define coeff0 0 +#define coeff1 0 +#define coeff2 0 +#define coeff3 0 +#define coeff4 0 +#define coeff5 0 + +AnalogIn adc(A0); //Entrée de l'ADC +Serial pc(USBTX, USBRX); // tx, rx + +float readValue; +float distance; int main() { while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + //Lecture de la valeur de l'ADC + readValue = (adc.read() * 3.3); //La valeur est entre 0-100% du voltage de référence qui est 3,3v. + //Donc je le mulitplie par 3,3 pour obtenir la vraie tension. + pc.printf("Valeur lue de l'ADC: %f\n", readValue); + + //Calcul de la régression + distance = ((coeff5 * powf(readValue, 5.0)) + (coeff4 * powf(readValue, 4.0)) + (coeff3 * powf(readValue, 3.0)) + (coeff2 * powf(readValue, 2.0)) + (coeff1 * readValue) + coeff0); + pc.printf("La position du bras est a: %f\n", readValue); } }