Skip to content

Instantly share code, notes, and snippets.

@haru01
Created August 22, 2016 12:35
Show Gist options
  • Save haru01/d085d4629357ac182b297b2e030f1208 to your computer and use it in GitHub Desktop.
Save haru01/d085d4629357ac182b297b2e030f1208 to your computer and use it in GitHub Desktop.
ピコピコぴー
#include <Tone.h>
#include "Ultrasonic.h"
Tone notePlayer;
Ultrasonic ultrasonic(7);
void setup(void)
{
notePlayer.begin(8);
}
void loop(void)
{
long range = ultrasonic.MeasureInCentimeters();
long delay_length = range * 3 + 100;
if (range >= 1) {
notePlayer.play(2252,50);
delay(delay_length);
notePlayer.play(2000,50);
delay(delay_length);
} else {
notePlayer.play(2500,2000);
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment