Oke i have put some work in it to try things out and make things work and understand it better, this is what i got so far:
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- TTLFO - an Arduino-based Tap Tempo LFO
- RonaldB, 20-08-2008
*/
const int pinPwmout = 9;
int buttonPressed = 2;
int ledPin = 13;
int val;
int numberOfButtonPresses = 0;
long int startTime;
long int endTime;
long int tempo; //time between tabs
void setup ()
{
pinMode(pinPwmout, OUTPUT);
pinMode(buttonPressed, INPUT);
pinMode(ledPin, OUTPUT);
}
extern volatile unsigned long timer0_overflow_count;
void resetMillis()
{
cli(); // disable interrupts
timer0_overflow_count = 0;
sei(); // enable interrupts
}
void loop()
{
if(buttonPressed && numberOfButtonPresses == 0){
resetMillis();
startTime = millis(); //store start time
numberOfButtonPresses++;
}
if(buttonPressed && numberOfButtonPresses == 1) {
endTime = millis(); //store the "end time"
tempo = 2000;
numberOfButtonPresses=0; //reset button counter for the next time
digitalWrite (pinPwmout, HIGH); //square wave output on PWM pin 9
delay (tempo);
digitalWrite (pinPwmout, LOW);
delay (tempo);
}
}
I have put a delay of 2000 in the tempo just to see if that is working.
Well the PWM is working at 2000ms on and off, so thats working.
Only when I put in this line:
tempo = startTime - endTime
The LED is flashing really fast (at least i think). Could this be a debounce thing?
How would i get this thing work so it reads the correct tempo between tabs.
thanks in advance
best regards
Ronald