Bonjour, J'aimerais réaliser une girouette qui marche a base d’Arduino. Malheureusement, Je suis débutant en langage Arduino et j'ai un peu de mal avec le code.
Le système marcha avec 6 leds et 6 photorésistance. Chaque photorésistance correspond a un bit. Vous trouverez une meilleur description du projet sur ce site : [URL="https://www.yoctopuce.com/FR/article/comment-mesurer-le-vent-partie-2"]. L'affichage se fera sur un écran LCD
Merci d'avance !


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
#include <LiquidCrystal_I2C.h> 
// En cas de non fonctionnement, mettez la ligne 8 en
// commentaire et retirez le commentaire à la ligne 9.
LiquidCrystal_I2C lcd(0x27, 20, 4); // ligne 8
//LiquidCrystal_I2C lcd(0x3F,20,4); // ligne 9
void setup()
int 
const int Led = 1;     // Définition des Leds
const int phre = 1;    // definition borne positive photoresistance
int Pr1 = A1;          // Déclaration broche photorésistance 1
int Pr2 = A2;          // Déclaration broche photorésistance 2
int Pr3 = A3;          // Déclaration broche photorésistance 3
int Pr4 = A4;          // Déclaration broche photorésistance 4
int Pr5 = A5;          // Déclaration broche photorésistance 5
int bit0 = 0;
int bit1 = 0;
int bit2 = 0;
int bit3 = 0;
int bit4 = 0;
 
void setup() {
 pinMode(Led, OUTPUT); //definition de la broche led comme sortie
 pinMode(phre, OUTPUT); //definition de la broche positive phre comme sortie
 pinMode(Pr1, INPUT);   //definition de la broche photoresistance1 comme entrée
 pinMode(Pr2, INPUT);   //definition de la broche photoresistance2 comme entrée
 pinMode(Pr3, INPUT);   //definition de la broche photoresistance3 comme entrée
 pinMode(Pr4, INPUT);   //definition de la broche photoresistance4 comme entrée
 pinMode(Pr5, INPUT);   //definition de la broche photoresistance5 comme entrée
 Serial.begin(9600);
 lcd.init(); // initialisation de l'afficheur
}
 
 
void loop() {
digitalWrite(Led, HIGH);//leds allumées
digitalWrite(phre, HIGH);
int val = analogRead(A0); // Un entier pour contenir une valeur variant de 0 à 1023 
  Serial.println(val);
  delay(1);
lcd.backlight(); // active le rétro-éclairage
lcd.setCursor(0, 0); // se positionner à la première ligne
lcd.print("       ");  // Afficher le mot 'carte'
lcd.setCursor(0,1);  // se positionner à la deuxième ligne
lcd.print("de texte"); // Afficher le mot 'Arduino'
}
 
void getDirVent()
  bit0 = not(digitalRead(Pr1));
  bit1 = not(digitalRead(Pr2));
  bit2 = not(digitalRead(Pr3));
  bit3 = not(digitalRead(Pr4));
  bit4 = not(digitalRead(Pr5));
 
  girouette =  (bit4 * 16) + (bit3 * 8) + (bit2 * 4) + (bit1 * 2) + bit0;
 
  Serial.print(bit0); Serial.print(bit1); Serial.print(bit2); Serial.print(bit3); Serial.print(bit4);
  Serial.print(" => ");
  Serial.print(girouette);
  Serial.print(" Orientation");
  switch (girouette) {
    case 24: dirVent="N"; break;
    case 10: dirVent="NE"; break;
    case 18: dirVent="E"; break;
    //case 18: dirVent="SE"; break;
    case 16: dirVent="S"; break;
    case 2: dirVent="SW"; break;
    case 26: dirVent="O"; break;
    case 8: dirVent="NO"; break;
    default: dirVent="N"; break; 
  }
 
 
}