Permet de lire et de stocker dans des variables publiques la direction pointées par la girouette WS1080.

Dependents:   test_girouette_library

GirouetteWD1080.cpp

Committer:
Station_Meteo_Laos
Date:
2019-05-20
Revision:
0:493f86ea1ecb
Child:
1:4c8b15e19600

File content as of revision 0:493f86ea1ecb:

#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;
}