Blame view

code_arduino/Test IMA3 P2/test/test.ino 664 Bytes
a4d85595   aknockae   Ajout de serialAr...
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
  /* Utilisation du capteur Ultrason HC-SR04 */
  
  // définition des broches utilisées
  int trig1 = 7;
  int echo1 = 6;
  
  int trig2 = 8;
  int echo2 = 5;
  long lecture_echo;
  long cm;
  
  void setup()
  {
    pinMode(trig1, OUTPUT);
    digitalWrite(trig1, LOW);
    pinMode(echo1, INPUT);
    
    pinMode(trig2, OUTPUT);
    digitalWrite(trig2, LOW);
    pinMode(echo2, INPUT);
    Serial.begin(9600);
  }
  
  void loop()
  {
    digitalWrite(trig1, HIGH);
    digitalWrite(trig2, HIGH);
    delayMicroseconds(10);
    digitalWrite(trig1, LOW);
    digitalWrite(trig2, LOW);
    lecture_echo = pulseIn(echo2, HIGH);
    cm = lecture_echo / 58;
    Serial.print("Distancem : ");
    Serial.println(cm);
    delay(500);
  }