Permet de lire et de stocker dans des variables publiques la direction pointées par la girouette WS1080.
Dependents: test_girouette_library
GirouetteWD1080.cpp@2:6d392919b388, 2019-05-20 (annotated)
- Committer:
- Station_Meteo_Laos
- Date:
- Mon May 20 08:45:58 2019 +0000
- Revision:
- 2:6d392919b388
- Parent:
- 1:4c8b15e19600
- Child:
- 4:dfa695d9c256
Permet de lire la girouette WD1080 et de stocker dans une variable publique (de type string ou de type int) la direction pointee par la girouette.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Station_Meteo_Laos | 0:493f86ea1ecb | 1 | #include "GirouetteWD1080.h" |
Station_Meteo_Laos | 0:493f86ea1ecb | 2 | #include "mbed.h" |
Station_Meteo_Laos | 0:493f86ea1ecb | 3 | |
Station_Meteo_Laos | 0:493f86ea1ecb | 4 | |
Station_Meteo_Laos | 0:493f86ea1ecb | 5 | GirouetteWD1080::GirouetteWD1080(PinName analog_pin):girouette(analog_pin) |
Station_Meteo_Laos | 0:493f86ea1ecb | 6 | { |
Station_Meteo_Laos | 0:493f86ea1ecb | 7 | } |
Station_Meteo_Laos | 0:493f86ea1ecb | 8 | |
Station_Meteo_Laos | 1:4c8b15e19600 | 9 | // Lit les différentes valeurs donné par la GirouetteWD1080 |
Station_Meteo_Laos | 1:4c8b15e19600 | 10 | //En déduit la direction inidquée par la girouette |
Station_Meteo_Laos | 1:4c8b15e19600 | 11 | |
Station_Meteo_Laos | 2:6d392919b388 | 12 | // => /!\ Les pôles de réfèrence sont sculptés sur le pied de la girouette /!\ |
Station_Meteo_Laos | 0:493f86ea1ecb | 13 | |
Station_Meteo_Laos | 2:6d392919b388 | 14 | bool GirouetteWD1080::read_string( ) |
Station_Meteo_Laos | 0:493f86ea1ecb | 15 | { |
Station_Meteo_Laos | 0:493f86ea1ecb | 16 | uint16_t positions[8] = {770, 200, 53, 30, 13, 105, 350, 550}, girou, i=0; |
Station_Meteo_Laos | 0:493f86ea1ecb | 17 | string directions[9]={"O","S-O","S","S-E","E","N-E","N","N-O", "ERR"}; |
Station_Meteo_Laos | 0:493f86ea1ecb | 18 | |
Station_Meteo_Laos | 0:493f86ea1ecb | 19 | girou = int(girouette.read()*1000.0f); |
Station_Meteo_Laos | 0:493f86ea1ecb | 20 | |
Station_Meteo_Laos | 0:493f86ea1ecb | 21 | for(i=0; i<9;i++){ |
Station_Meteo_Laos | 0:493f86ea1ecb | 22 | if( (positions[i]-10)<=girou && (positions[i]+10)>=girou){ |
Station_Meteo_Laos | 2:6d392919b388 | 23 | direction_string = directions[i]; |
Station_Meteo_Laos | 0:493f86ea1ecb | 24 | return true; |
Station_Meteo_Laos | 0:493f86ea1ecb | 25 | } |
Station_Meteo_Laos | 0:493f86ea1ecb | 26 | } |
Station_Meteo_Laos | 0:493f86ea1ecb | 27 | |
Station_Meteo_Laos | 2:6d392919b388 | 28 | direction_string = directions[8]; |
Station_Meteo_Laos | 2:6d392919b388 | 29 | return false; |
Station_Meteo_Laos | 2:6d392919b388 | 30 | } |
Station_Meteo_Laos | 2:6d392919b388 | 31 | |
Station_Meteo_Laos | 2:6d392919b388 | 32 | bool GirouetteWD1080::read_int( ) |
Station_Meteo_Laos | 2:6d392919b388 | 33 | { |
Station_Meteo_Laos | 2:6d392919b388 | 34 | uint16_t positions[8] = {770, 200, 53, 30, 13, 105, 350, 550}, girou, i=0; |
Station_Meteo_Laos | 2:6d392919b388 | 35 | |
Station_Meteo_Laos | 2:6d392919b388 | 36 | girou = int(girouette.read()*1000.0f); |
Station_Meteo_Laos | 2:6d392919b388 | 37 | |
Station_Meteo_Laos | 2:6d392919b388 | 38 | for(i=0; i<9;i++){ |
Station_Meteo_Laos | 2:6d392919b388 | 39 | if( (positions[i]-10)<=girou && (positions[i]+10)>=girou){ |
Station_Meteo_Laos | 2:6d392919b388 | 40 | direction_int = i; |
Station_Meteo_Laos | 2:6d392919b388 | 41 | return true; |
Station_Meteo_Laos | 2:6d392919b388 | 42 | } |
Station_Meteo_Laos | 2:6d392919b388 | 43 | } |
Station_Meteo_Laos | 2:6d392919b388 | 44 | |
Station_Meteo_Laos | 2:6d392919b388 | 45 | direction_int = 255; |
Station_Meteo_Laos | 0:493f86ea1ecb | 46 | return false; |
Station_Meteo_Laos | 0:493f86ea1ecb | 47 | } |
Station_Meteo_Laos | 0:493f86ea1ecb | 48 | |
Station_Meteo_Laos | 0:493f86ea1ecb | 49 |