Last active
August 10, 2016 21:54
-
-
Save haru01/912400e8076aafcc1384ab7d0ea8acf9 to your computer and use it in GitHub Desktop.
ultrasonic で距離を測定し rgb_lcd で表示する
This file contains hidden or 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
#include "Ultrasonic.h" | |
#include "rgb_lcd.h" | |
#include <Wire.h> | |
rgb_lcd lcd; | |
Ultrasonic ultrasonic(7); | |
void setup() | |
{ | |
lcd.begin(16, 0); | |
} | |
void loop() | |
{ | |
delay(500); | |
lcd.clear(); | |
long range = ultrasonic.MeasureInCentimeters(); | |
setLcdColor(range); | |
printRange(range); | |
} | |
void setLcdGreen() { | |
lcd.setRGB(0, 255, 0); | |
} | |
void setLcdRed() | |
{ | |
lcd.setRGB(255, 0, 0); | |
} | |
void setLcdColor(long range) | |
{ | |
if (range < 30) { | |
setLcdRed(); | |
} else { | |
setLcdGreen(); | |
} | |
} | |
void printRange(long range) | |
{ | |
lcd.print(range); | |
lcd.print(" cm"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment