Last active
March 18, 2017 09:34
-
-
Save maxpromer/ec5c26edc6d996f986372997474f0db9 to your computer and use it in GitHub Desktop.
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
/* | |
* Codeing By IOXhop : www.ioxhop.com | |
*/ | |
#include <SoftwareSerial.h>; | |
#define TX_PIN 2 // Pin connect to Tx | |
#define RX_PIN 3 // Pin connect to Rx | |
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Rx, Tx | |
void setup() { | |
Serial.begin(9600); | |
mySerial.begin(9600); | |
Serial.println("Distance"); | |
} | |
void loop() { | |
mySerial_flush(); | |
mySerial.write(???); | |
delay(100); | |
if(mySerial.available() < 2) { | |
Serial.println("Error read"); | |
delay(500); | |
return; | |
} | |
unsigned int distance = mySerial.read() ??? mySerial.read(); | |
Serial.print(distance); | |
Serial.print(" mm.\t"); | |
delay(500); | |
} | |
void mySerial_flush() { | |
while(mySerial.available()) | |
mySerial.read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment