Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4.  
  5. #include <pigpio.h>
  6.  
  7. /*
  8. gcc -Wall -pthread -o servo_demo servo_demo.c -lpigpio
  9.  
  10. */
  11.  
  12. #define GPIO_PIN 14
  13.  
  14. #define MIN_WIDTH 1000
  15. #define MAX_WIDTH 2000
  16.  
  17. int alive = 1;
  18. int value = 1500;
  19. void stop(int signum)
  20. {
  21. alive = 0;
  22. }
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.  
  27. //init gpio lib
  28. if (gpioInitialise() < 0) return -1;
  29. //init signal interrupt
  30. gpioSetSignalFunc(SIGINT, stop);
  31.  
  32.  
  33. if (argc != 1) {
  34. printf("No CLA are supported!\n");
  35. exit(0);
  36. }
  37.  
  38.  
  39.  
  40. printf("Welcome!\n.\n.\n.\n.\n.\n.\n.\nNow accepting values 1000-2000\nPress control-C to stop.\n");
  41.  
  42. while(alive)
  43. {
  44.  
  45. gpioServo(GPIO_PIN, value);
  46. if(scanf("%d", &value) == EOF){
  47. printf("Invalid Input!\n");
  48. break;
  49. }
  50. }
  51.  
  52. printf("\nClosing up!\n");
  53.  
  54. gpioServo(GPIO_PIN, 0);
  55. gpioTerminate();
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement