Skip to content

Instantly share code, notes, and snippets.

@shockwaves
Created February 19, 2019 10:01
Show Gist options
  • Save shockwaves/265d8e47ae33bc779f7c501303187320 to your computer and use it in GitHub Desktop.
Save shockwaves/265d8e47ae33bc779f7c501303187320 to your computer and use it in GitHub Desktop.
arduino-rangefinder.ino
/*
*
* 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