Strange breed, these open license folks... they are eager to help someone who has bothered to do some research and experimentation, and tried to learn on their own. they freely exchange information and experiences on how to use the hardware and software, but want to get paid for doing somebody's work for them....
The rule here is 'show that you have tried to learn by doing, then ask for help (show your work on the back of the exam)'.
Probably not what you wanted to hear, but sometimes, life is a bear.
For starts you read the Read Before Posting thread and see to put code tags around your code so it's readable in html.
If you are going to time with 16 bit values then use word instead of int. You can time up to 65.535 seconds with type word (Arduino unsigned 16 bit) counting the low 16 bits of millis. Note that occasionally you will be 1 ms off using millis(), when it matters use micros().
int x=0;
int lastx=0;
int lasty=0;
int LastTime=0;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
......
if(BeatComplete)
{
BPM=millis()-LastTime;
BPM=int(60/(float(BPM)/1000));
BPMTiming=false;
BeatComplete=false;
}
if(BPMTiming==false)
{
LastTime=millis();
BPMTiming=true;
}
is better written as
int x=0;
int lastx=0;
int lasty=0; // howcome there's a lasty but no y?
bool BPMTiming;
bool BeatComplete=false;
unsigned long LastTime; // declared variables default to zero
unsigned long BPM; // is unsigned long to be same type math with timer variables and millis() UL return.
......
if(BeatComplete)
{
BPM=millis()-LastTime; // now the ms time since last beat, it was -- not always going to work like you thought.
BPM=60000/BPM; // y=a/(b/c)=a*c/b, algebra. [b]with integers do your multiplies before divides to get less roundoff[/b]
BPMTiming=false;
BeatComplete=false;
}
if(BPMTiming==false) // this will always run if (BeatComplete)
{
LastTime=millis();
BPMTiming=true; // this switches BPMTiming as set in if (BeatComplete) from false to true
}
Code is a DIY logic puzzle. If it works without glitches then you solved it. Till then use logic to craft and debug
your code.