Created
January 23, 2020 06:18
-
-
Save suadanwar/9e08dd78aedf6da2690a7424bafd6dc5 to your computer and use it in GitHub Desktop.
This sample code is for Smart Blind Stick Tutorial.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define TRIGPIN1 2 | |
#define ECHOPIN1 3 | |
#define TRIGPIN2 5 | |
#define ECHOPIN2 6 | |
#define PIEZO 8 | |
// defines variables | |
long Duration1; | |
int Distance1; | |
long Duration2; | |
int Distance2; | |
void setup() { | |
pinMode(TRIGPIN1, OUTPUT); | |
pinMode(ECHOPIN1, INPUT); | |
pinMode(TRIGPIN2, OUTPUT); | |
pinMode(ECHOPIN2, INPUT); | |
pinMode(PIEZO, OUTPUT); | |
Serial.begin(9600); | |
} | |
void Activate1() { | |
digitalWrite(TRIGPIN1, LOW); | |
delayMicroseconds(2); | |
digitalWrite(TRIGPIN1, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(TRIGPIN1, LOW); | |
} | |
void Activate2() { | |
digitalWrite(TRIGPIN2, LOW); | |
delayMicroseconds(2); | |
digitalWrite(TRIGPIN2, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(TRIGPIN2, LOW); | |
} | |
void loop() { | |
Activate1(); | |
Duration1 = pulseIn(ECHOPIN1, HIGH); | |
Distance1 = Duration1 * 0.017; | |
Activate2(); | |
Duration2 = pulseIn(ECHOPIN2, HIGH); | |
Distance2 = Duration2 * 0.017; | |
Serial.print(Distance1); | |
Serial.print(" "); | |
Serial.println(Distance2); | |
if (Distance1 <= 10 || Distance2 <= 10) { | |
tone(PIEZO, 1000, 300); | |
delay(450); | |
} | |
else { | |
noTone; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ทำไมมันร้องไม่หยุดเลยละครับ