Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <button.h>
  6. #include <console.h>
  7. #include <timer.h>
  8. #include <led.h>
  9.  
  10. void send() {
  11. led_on(1);
  12. delay_ms(5000);
  13. led_on(0);
  14. printf("!\n");
  15. //fflush();
  16. delay_ms(1000);
  17. led_off(0);
  18. led_off(1);
  19. }
  20.  
  21. static void button_callback(int btn_num, int val,
  22. __attribute__ ((unused)) int arg2,
  23. __attribute__ ((unsued)) void *ud) {
  24.  
  25. if(val == 1) {
  26. send();
  27. }
  28. }
  29.  
  30. int main(void) {
  31.  
  32. button_subscribe(button_callback, NULL);
  33.  
  34. int count = button_count();
  35. for(int i = 0; i<count; i++) {
  36. button_enable_interrupt(i);
  37. }
  38.  
  39. while(1) {
  40. int c = getch();
  41.  
  42. if(c == TOCK_FAIL) {
  43. printf("\n getch() failed\n");
  44. }
  45. else if(c == 33) {
  46. send();
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement