Hey guys, I'm working on a project that warrants running a button sequence(along with the timing) on an LED. When the first button is pressed, the arduino starts reading the status of the second button. The pressing sequence on the second button is stored until the first button is pressed again. now, the button sequence that was stored, is replicated on the LED. I came up with a code that tries to do the basic functionality except the LED part. but I'm not getting the desired output. Can you guys check it for me ?
#include <Debounce.h>
const byte SWITCH = 2;
const byte SWITCH1 = 4;
const byte LED = 9;
int count = 0;
unsigned long startTime = 0;
unsigned long endTime = 0;
unsigned long startTime1 = 0;
unsigned long endTime1 = 0;
unsigned long elapsedTime = 0;
unsigned long elapsedTime1 = 0;
const byte debounceDelayTime = 50;
int a[100],i,j,flag = 0,flag1 = 0,b=0;
Debounce debouncer = Debounce(debounceDelayTime, SWITCH);
void setup(){
Serial.begin(9600);
pinMode(SWITCH, INPUT_PULLUP);
pinMode(SWITCH1, INPUT_PULLUP);
pinMode(LED, OUTPUT);
}
void loop(){
fun();
while(count == 1)
{
fun();
if(count == 1)
{
if(debouncer.update())
{
if(debouncer.read() == 1)
{
startTime = millis();
endTime1 = millis();
elapsedTime1 = endTime1 - startTime1;
Serial.println("Button Pressed");
Serial.println("Button Released for:");
Serial.print(elapsedTime1);
if(flag1 == 0)
{
for(j=b;j<100;j+2)
{
while(flag1 == 0)
{
b=j+2;
a[j] = elapsedTime;
flag1 = 1;
}
}
}
flag1 = 0;
}
else if(debouncer.read() == 0)
{
endTime = millis();
startTime1 = millis();
Serial.println("Button Released");
elapsedTime = endTime - startTime;
Serial.println("Button Held Down For ");
Serial.print(elapsedTime);
Serial.println(" ms.");
if(flag == 0)
{
for(j=b;j<100;j+2)
{
while(flag == 0)
{
b=j+2;
a[j] = elapsedTime;
flag = 1;
}
}
}
flag = 0;
}
}
}
else
count = 0;
}
Serial.println("A*=");*
for(i=0;i<100;i++)
{ *
_Serial.println(a);_
_}_
_}_
void fun()
_{_
_ if (digitalRead(SWITCH1) == 1)_
_ {_
_ count++;_
_ while (digitalRead(SWITCH1) == 1);_
_ {_
_ delay(75);_
_ }_
_ }_
_ else*_
* count = 1;*
}