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 2:92e518f9238d, committed 2017-04-01
- Comitter:
- marc1119
- Date:
- Sat Apr 01 20:21:30 2017 +0000
- Parent:
- 1:5ced6fbeaf18
- Child:
- 3:ca15e31b2386
- Commit message:
- version 2
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Apr 01 02:11:04 2017 +0000 +++ b/main.cpp Sat Apr 01 20:21:30 2017 +0000 @@ -2,28 +2,30 @@ #include <math.h> //Coefficients pour la régression. -#define coeff0 0 -#define coeff1 0 -#define coeff2 0 -#define coeff3 0 -#define coeff4 0 -#define coeff5 0 +const float coeff0 = 3.214795; +const float coeff1 = 0.03762076; +const float coeff2 = -0.00688375; +const float coeff3 = 0.0001416016; +const float coeff4 = -0.0000007340037; +const float coeff5 = -0.000000002012925; -AnalogIn adc(A0); //Entrée de l'ADC +AnalogIn adc(p19); //Entrée de l'ADC Serial pc(USBTX, USBRX); // tx, rx -float readValue; float distance; int main() { while(1) { - //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. + + //Lecture de la valeur de l'ADC + uint16_t 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); + wait_ms(600); //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); + pc.printf("La position du bras est a: %f\n", distance); } }