I'm using MC Audio Development kit trying to make use of the buttons. I've decided to use the lib_gpio for this and it seems my setup for that is working correctly. Everything compiles and runs, but my gain is always increasing, like button_1.input() is always active. Pushing the buttons does effect the loudness, but things seem to have a mind of their own. Am I using the lib_gpio correctly?
Code: Select all
void GAIN_CNTRL(client i2c_master_if i2c, client input_gpio_if button_1, client input_gpio_if button_2, client input_gpio_if button_3){
unsigned char pga_gain = 0x0c;
//Initial button event state, active low
button_1.event_when_pins_eq(0);
button_2.event_when_pins_eq(0);
button_3.event_when_pins_eq(0);
while(1){
select{
case button_1.event():
if(button_1.input() == 0){
++pga_gain;
i2c.write_reg(0x4a, 0x01, pga_gain);
// Set button event state to active high for debounce
button_1.event_when_pins_eq(1);
} else{
//Debounce
delay_milliseconds(50);
button_1.event_when_pins_eq(0);
}
break;
case button_2.event():
if(button_2.input() == 0){
--pga_gain;
i2c.write_reg(0x4a, 0x01, pga_gain);
// Set button event state to active high for debounce
button_2.event_when_pins_eq(1);
} else{
//Debounce
delay_milliseconds(50);
button_2.event_when_pins_eq(0);
}
break;
}
}
}