in my workspace I want to include a button to control audio.
On my board the button is connected to an 4-Bit port (port 0), which means, that I use the value 0x8 to check, if the button was pressed.
I also checked out the button-handle example where I use the following code to try (code is already modified):
Code: Select all
[[combinable]]
void task1a(port p_button, streaming chanend c_ButtonVal)
{
int current_val = 0;
int is_stable = 1;
timer tmr;
const unsigned debounce_delay_ms = 50;
unsigned debounce_timeout;
while (1) {
select {
// If the button is "stable", react when the I/O pin changes value
case is_stable => p_button when pinsneq(current_val) :> current_val:
if (current_val == 0x8) {
c_ButtonVal<:0;
} else {
c_ButtonVal<:1;
}
is_stable = 0;
int current_time;
tmr :> current_time;
// Calculate time to event after debounce period
// note that XS1_TIMER_HZ is defined in timer.h
debounce_timeout = current_time + (debounce_delay_ms * XS1_TIMER_HZ);
break;
// If the button is not stable (i.e. bouncing around) then select
// when we the timer reaches the timeout to renter a stable period
case !is_stable => tmr when timerafter(debounce_timeout) :> void:
is_stable = 1;
break;
}
}
}
I use the following port:
Code: Select all
on tile[1] : port p_button = XS1_PORT_4B;
Could you help me, why it doesn't change my audio-signal? I just want to mute the audio signal while pressing/hitting the button.
Thank you.