Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <pigpio.h>
- /*
- gcc -Wall -pthread -o servo_demo servo_demo.c -lpigpio
- */
- #define GPIO_PIN 14
- #define MIN_WIDTH 1000
- #define MAX_WIDTH 2000
- int alive = 1;
- int value = 1500;
- void stop(int signum)
- {
- alive = 0;
- }
- int main(int argc, char *argv[])
- {
- //init gpio lib
- if (gpioInitialise() < 0) return -1;
- //init signal interrupt
- gpioSetSignalFunc(SIGINT, stop);
- if (argc != 1) {
- printf("No CLA are supported!\n");
- exit(0);
- }
- printf("Welcome!\n.\n.\n.\n.\n.\n.\n.\nNow accepting values 1000-2000\nPress control-C to stop.\n");
- while(alive)
- {
- gpioServo(GPIO_PIN, value);
- if(scanf("%d", &value) == EOF){
- printf("Invalid Input!\n");
- break;
- }
- }
- printf("\nClosing up!\n");
- gpioServo(GPIO_PIN, 0);
- gpioTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement