TCCR0 |= (1 << CS00) | (1<<CS02); // timer 0 prescaler 1024, overflow at FOSC/1024/256
Then wait for Timer 0 overflow before sampling the buttons
// Sample controllers each 16ms for 16MHz crystal (22ms for 12MHz)
if (TIFR & (1<<TOV0)) {
Get_digital_controller_data();
TIFR |= (1<<TOV0); // reset overflow flag
}
This prevents bouncing at later part of the code which sends a packed each time it detects any change in the controllers.
...
else
{// or if data has changed
if (memcmp(&gamepad_report_1, &gamepad_report_1_old, sizeof(gamepad_report_t)) != 0)
{
to_send = 1;
}
}
...
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.