Hi
I need to Send one character from mobile. based on the character I need to glow the LEDs which is placed on DK. How can I achieve this is there any sample available for reference?
Thanks & Regards
Navin
Hi Navin,
Mr.NCK said:Let me know how can I achieve this.
This lesson contains what you need to learn how to use the GPIO interface. Use this with the peripheral_uart sample and the UART topic I linked in the previous reply.
What you want to do is to in steps
1) Implement the functionality that allows you to send a something over bluetooth/UART (peripheral_uart and central_uart are great for this)
2) Use what is sent over Bluetooth/UART as arguments in a callback function to trigger what leds are supposed to be triggered. (Academy UART and GPIO topics). Take a closer look at this function from the UART exercise to see how you can implement this.
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
switch (evt->type) {
case UART_RX_RDY:
if((evt->data.rx.len) == 1){
if(evt->data.rx.buf[evt->data.rx.offset] == '1')
gpio_pin_toggle(leds,PIN0);
else if (evt->data.rx.buf[evt->data.rx.offset] == '2')
gpio_pin_toggle(leds,PIN1);
else if (evt->data.rx.buf[evt->data.rx.offset] == '3')
gpio_pin_toggle(leds,PIN2);
break;
}
case UART_RX_DISABLED:
uart_rx_enable(dev ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
break;
default:
break;
}
}
This function reads the input and toggles the lights corresponding to the input char. Do the same, but only with button presses instead according to 3)
3) Investigate reading buttons and controlling LEDS to see how you can
4) Change 2) to send button presses instead of sending a user written char to trigger the light, i.e merge 2) with 3)
I hope this helps!
Kind regards,
Andreas