XMC2Go and a Button

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi all,

Trying to get a XMC2Go and a pushbutton to work together to control an LED, am a bit lost though. Anyone have any examples they can point me to ?
0 Likes
1 Reply
DRubeša
Employee
Employee
First solution authored First like received
So, there is a plenty of ways to perform the LED control using pushbutton, and this is only one solution. I´ve used the approach with XMC Libraries while it´s more user-friendly than direct register access approach and you don´t need to know who to use DAVE APPs.

#include 

#define PUSHBUTTON ???? // define the port and the pin where you´ve connected pushbutton
#define LED1 P1_1

int main(void)
{

XMC_GPIO_SetMode(PUSHBUTTON, XMC_GPIO_MODE_INPUT_TRISTATE);
XMC_GPIO_SetMode(LED1, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);

while(1U)
{

if(!XMC_GPIO_GetInput(PUSHBUTTON))
{
XMC_GPIO_SetOutputHigh(LED1);
}
else
{
XMC_GPIO_SetOutputLow(LED1);
}

}
}


I don´t know how you´re going to connect the pushbutton to the XMC2Go pin (while the board itself doesn´t provide pushbutton), so maybe your if-statement is going to be different. I´ve tested the example on the board that has a pushbutton and the pushbotton is connected to the pin as following:
2283.attach
0 Likes