Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Last active March 18, 2017 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxpromer/ec5c26edc6d996f986372997474f0db9 to your computer and use it in GitHub Desktop.
Save maxpromer/ec5c26edc6d996f986372997474f0db9 to your computer and use it in GitHub Desktop.
/*
* 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