I am looking help to write code for switch
as I know , we read and debounce a mechanical switch as follow
1. if switch is not pressed, return switch not pressed
2. if switch is pressed, wait for the debounces period
Then
a. if switch is no longer preesed , return switch not pressed
b. if switch is still pressed , return switch pressed
I am converting this logic into code
My question is : What would be the best way to do this in coding
as I know , we read and debounce a mechanical switch as follow
1. if switch is not pressed, return switch not pressed
2. if switch is pressed, wait for the debounces period
Then
a. if switch is no longer preesed , return switch not pressed
b. if switch is still pressed , return switch pressed
I am converting this logic into code
Code:
void main(void)
{
while(1)
{
}
}
int switch_get_input (int debounces_period )
{
return_value = switch_not_pressed;
if (switch_pin == 0) // switch is pressed
{
debounces_time(debounces_period);
if (switch_pin ==0)
{
return_value = switch_pressed;
}
}
return return_value;
}