Permet de lire et de stocker dans des variables publiques la direction pointées par la girouette WS1080.
Dependents: test_girouette_library
Diff: GirouetteWD1080.cpp
- Revision:
- 0:493f86ea1ecb
- Child:
- 1:4c8b15e19600
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GirouetteWD1080.cpp Mon May 20 08:14:27 2019 +0000 @@ -0,0 +1,29 @@ +#include "GirouetteWD1080.h" +#include "mbed.h" + + +GirouetteWD1080::GirouetteWD1080(PinName analog_pin):girouette(analog_pin) +{ +} + +// GirouetteWD1080 + +bool GirouetteWD1080::read( ) +{ + uint16_t positions[8] = {770, 200, 53, 30, 13, 105, 350, 550}, girou, i=0; + string directions[9]={"O","S-O","S","S-E","E","N-E","N","N-O", "ERR"}; + + girou = int(girouette.read()*1000.0f); + + for(i=0; i<9;i++){ + if( (positions[i]-10)<=girou && (positions[i]+10)>=girou){ + direction = directions[i]; + return true; + } + } + + direction = directions[8]; + return false; +} + +