Well, I made a very simple metronome, that sends a blink and a sound beep to a buzzer, with arduino. Te idea was to build it with as less delays as possible. The code is still very "alpha" and poorly commented, I will expand it to give it more functions.
// Metroduino 0.1
// (c) Ricardo Lameiro ricardolameiro a t g_m a_ i_ l . com
//
//This software is OpenSource under the GPL license
//the license is at http://www.gnu.org/copyleft/gpl.html
// You are free to distribute and modify provide that you don't harm the author
//
// I wish to thank dfletcher_ @ #arduino @ freenode for the help in the time engine
#include <MsTimer2.h>
long counter = 0;
char rcv = 0;
long bpm = 120;
long time = 1000;
void flash() {
if (counter <= 100) {
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
analogWrite(9, 100);
//Serial.println(counter, DEC);
}
else {
digitalWrite(13, LOW);
digitalWrite(12, LOW);
analogWrite(9, 0);
//Serial.println(counter, DEC);
//Serial.println(time, DEC);
}
counter++;
if (counter >= time) counter = 0;
}
void timesetup(int t) {
MsTimer2::set(t, flash); // 500ms period
MsTimer2::start();
}
void updatebpm() {
time = (60.0 / bpm) * 1000;
Serial.println(time, DEC);
}
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
MsTimer2::set(1, flash); // 500ms period
MsTimer2::start();
Serial.begin(9600);
}
void update() {
if (rcv == 109)
{
bpm++;
Serial.print("BPM:");
Serial.println(bpm, DEC);
updatebpm();
}
else if (rcv == 108)
{
bpm--;
Serial.print("BPM:");
Serial.println(bpm, DEC);
updatebpm();
}
else
{
rcv = 0;
}
}
void loop() {
if (Serial.available() > 0){
rcv = Serial.read();
update();
}
}
A little video of it working: