Created
August 2, 2016 18:23
-
-
Save margyle/0a6f097eef315a4f4c319a0bc6ff4937 to your computer and use it in GitHub Desktop.
Arduino Simple Metronome
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
/* | |
Simple Metronome (RThurber) v1 | |
This example code is in the public domain. | |
*/ | |
// Pin 13 has an LED connected on most Arduino boards. | |
int led = 13; // LED and Piezo | |
int sensorPin = 0; // select the input pin for the potentiometer | |
int sensorValue = 0; | |
int metronomeBPM = 0; | |
int metronomePulse = 10; | |
int staticBPM = 60000; | |
int divisor = 0; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize the digital pin as an output. | |
pinMode(led, OUTPUT); | |
Serial.begin(9600); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
sensorValue = analogRead(sensorPin); | |
digitalWrite(led, HIGH); | |
delay(metronomePulse); // Use a 10 ms pulse for Piezo | |
digitalWrite(led, LOW); | |
delay(sensorValue); // Take potentiometer as the metronome interval (offset 10ms). | |
divisor = sensorValue + metronomePulse; | |
metronomeBPM = 60000 / divisor; | |
Serial.println(metronomeBPM); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment