Created
February 19, 2019 10:01
-
-
Save shockwaves/265d8e47ae33bc779f7c501303187320 to your computer and use it in GitHub Desktop.
arduino-rangefinder.ino
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
/* | |
* | |
* Radar/Rangefinder | |
* | |
*/ | |
#include <Ultrasonic.h> | |
#include "TM1637.h" | |
#define CLK 3 | |
#define DIO 2 | |
#define SPEAKER 4 | |
TM1637 screen(CLK,DIO); | |
Ultrasonic ultrasonic(12, 13); | |
int distance; | |
void setup() { | |
pinMode(SPEAKER, OUTPUT); | |
screen.set(BRIGHT_DARKEST); | |
screen.init(D4036B); | |
screen.display(8888); | |
delay(1500); | |
Serial.begin(9600); | |
} | |
void beep() { | |
digitalWrite(SPEAKER, HIGH); | |
delay(5); | |
digitalWrite(SPEAKER, LOW); | |
} | |
void loop() { | |
distance = ultrasonic.read(); | |
screen.display(distance); | |
beep(); | |
Serial.print("Distance in CM: "); | |
Serial.println(distance); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment