Hi
I have the code below and i was hoping someone could just have a quick check through it and see if it does what I think it does.
I basically want to record a maximum of ten timings when a user presses a button. I want to store those timings in positions 1 - 10 of an array, positions 0, 11 - 12 are for other things.
I think the code below should do that ( i want the timings compounded on the last one):
void data_collector()
{
unsigned int datatable[30][12];
int i, j;
for (i = 0;i<30;i++)
{
for (j=0;j<12;j++)
{
datatable[i][j] = 0;//Filling all array posiitons with 0
}
}
for (i = 0;i<30;i++)
{
//function to begin collecting data
datatable[i][0] = i+1; //Column 1 of table is index number
while (PIND&(1<<PD6)); // loop here until first button press
TCNT0 = 0;
timer_tick=0;// here is where we start timing
_delay_ms(10); // delay for 1 ms to debounce button press
while (!(PIND&(1<<PD6))); // loop here until button is released
_delay_ms(10); // delay for 10 ms to debounce button release
for (j=0;j<10;j++)//Filling columns 1 - 10
{
while (PIND&(1<<PD6)); // loop here until second button press
datatable[i][j+1] = timer_tick; //get the value of the millisecond counter
_delay_ms(10); // delay for 1 ms to debounce button press
while (!(PIND&(1<<PD6))); // loop here until button is released
_delay_ms(10); // delay for 10 ms to debounce button release
}
// datatable[i][11] = //to be completed
//datatable[i][12] = //to be completed
}
}
Does that make sense?
I am worried about the delays for debounces - are these an effective way to avoid debouncing? Will they mess up my timings?
If the user wants to pull out before 10 timings have been taken, (by pressing another button say) can I just use an if break; command within the for loop?
Lastly, it is waiting for the button release, for accurate timings though everything should happen on the button press right?
I basically want to know if you guys would go about this the same way?
Thanks guys