Skip to content

Instantly share code, notes, and snippets.

@haru01
Last active August 10, 2016 21:54
Show Gist options
  • Save haru01/912400e8076aafcc1384ab7d0ea8acf9 to your computer and use it in GitHub Desktop.
Save haru01/912400e8076aafcc1384ab7d0ea8acf9 to your computer and use it in GitHub Desktop.
ultrasonic で距離を測定し rgb_lcd で表示する
#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