main.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-11-25 hywing first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include <board.h>
  13. #define LED0_PIN GET_PIN(B, 0)
  14. #define LED1_PIN GET_PIN(E, 1)
  15. #define LED2_PIN GET_PIN(B, 14)
  16. #define USER_KEY GET_PIN(C, 13)
  17. #define DELAY 500
  18. void irq_callback(void *arg)
  19. {
  20. if(rt_pin_read(USER_KEY) == 1)
  21. {
  22. rt_kprintf("Key pressed!\r\n");
  23. }
  24. }
  25. int main(void)
  26. {
  27. /* set GPIO pin mode to output */
  28. rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
  29. rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
  30. rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
  31. rt_pin_mode(USER_KEY, PIN_MODE_INPUT_PULLDOWN);
  32. rt_pin_attach_irq(USER_KEY, PIN_IRQ_MODE_RISING, irq_callback, RT_NULL);
  33. rt_pin_irq_enable(USER_KEY, PIN_IRQ_ENABLE);
  34. rt_kprintf("Welcome to the world of IoT Stuff!\r\n");
  35. while (1)
  36. {
  37. rt_pin_write(LED0_PIN, PIN_HIGH);
  38. rt_pin_write(LED1_PIN, PIN_LOW);
  39. rt_pin_write(LED2_PIN, PIN_LOW);
  40. rt_thread_mdelay(DELAY);
  41. rt_pin_write(LED0_PIN, PIN_LOW);
  42. rt_pin_write(LED1_PIN, PIN_HIGH);
  43. rt_pin_write(LED2_PIN, PIN_LOW);
  44. rt_thread_mdelay(DELAY);
  45. rt_pin_write(LED0_PIN, PIN_LOW);
  46. rt_pin_write(LED1_PIN, PIN_LOW);
  47. rt_pin_write(LED2_PIN, PIN_HIGH);
  48. rt_thread_mdelay(DELAY);
  49. rt_pin_write(LED0_PIN, PIN_LOW);
  50. rt_pin_write(LED1_PIN, PIN_HIGH);
  51. rt_pin_write(LED2_PIN, PIN_LOW);
  52. rt_thread_mdelay(DELAY);
  53. }
  54. }