Blame view

code arduino/test.ino 1.24 KB
c4726d68   aknockae   ajout du code ard...
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
  /* Utilisation du capteur Ultrason HC-SR04 */
  
  // définition des broches utilisées
  int trigA = 7;
  int echoA = 6;
  
  int trigB = 7;
  int echoB = 5;
  long timeAB;
  long timeBA;
  long C;
  long V;
  long speedofsoundmps = 340;
  
  void setup()
  {
    pinMode(trigA, OUTPUT);
    digitalWrite(trigA, LOW);
    pinMode(echoA, INPUT);
    
    pinMode(trigB, OUTPUT);
    digitalWrite(trigB, LOW);
    pinMode(echoB, INPUT);
    Serial.begin(9600);
  }
  
  void loop()
  {
    digitalWrite(trigA, LOW);
    delayMicroseconds(2);
    digitalWrite(trigA, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigA, LOW);
    timeAB = pulseIn(echoB, HIGH);
    //timeAB = timeAB-40;
    //Serial.println("Temps AB : ");
    //Serial.println(timeAB);
  
    delay(100);
  
    digitalWrite(trigB, LOW);
    delayMicroseconds(2);
    digitalWrite(trigB, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigB, LOW);
    timeBA = pulseIn(echoA, HIGH);
    //timeBA = timeBA-40;
    //Serial.println("Temps BA : ");
    //Serial.println(timeBA);
  
  
    C = (0.45/2)*((1e6/timeAB)+(1e6/timeBA));
    V = (0.45/2)*((1e6/timeAB)-(1e6/timeBA));
    //Serial.println("Vitesse c : ");
    //Serial.println(C); 
    //Serial.println() ;
    Serial.println("Vitesse du vent V : ");
    Serial.println(V);
    Serial.println();
    //Serial.println();
    //Serial.println();
    delay(1000);
  }