raspberrypi:pigpio
pigpio yra kita biblioteka kontroliuoti GPIO, jie turiu geresni/tikslesni DMA paremta softwarini PWM. PWM reikalingas servo motorams kontroliuoti.
#include <stdio.h> #include <stdlib.h> #include <signal.h> #include <termios.h> #include <unistd.h> #include <pigpio.h> // gcc -Wall -pthread -o pigpio_spwm pigpio_spwm.c -lpigpio -O3 // sudo ./pigpio_spwm int main(int argc, char *argv[]) { static struct termios oldt, newt; tcgetattr( STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr( STDIN_FILENO, TCSANOW, &newt); if (gpioInitialise() < 0) return -1; //gpioSetMode(21, PI_OUTPUT); //gpioSetPWMfrequency(21, 10000); //gpioSetPWMrange(21, 2000); int p = 0; printf("Press e to exit program\n"); printf("press q and w to increase and decrease software pwm\n"); int c; while((c=getchar())!= 'e') { if (c == 'q') p ++; if (c == 'w') p --; printf("%d \r",p); gpioPWM(21, p); } tcsetattr( STDIN_FILENO, TCSANOW, &oldt); return 0; }
raspberrypi/pigpio.txt · Last modified: by aistis
