#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define HIGH 1
#define LOW 0
#define ANALOG_PIN 0 // A0
#define PWM_PIN 0
#define PERIOD 1000000
bool pwmPin(int pin, int
period, int duty_cycle, int enable){
FILE * fd;
char fName[128];
if(( fd =
fopen("/sys/class/pwm/pwmchip0/export", "w")) == NULL) {
printf("Error: unable to export
pin\n");
return false;
}
fprintf(fd, "%d\n", pin);
fclose(fd);
sprintf(fName,
"/sys/class/pwm/pwmchip0/pwm%d/period", pin);
if((fd = fopen(fName, "w")) ==
NULL) {
printf("Error: can't open pin
period\n");
return false;
}
fprintf(fd, "%d\n", period);
fclose(fd);
sprintf(fName,
"/sys/class/pwm/pwmchip0/pwm%d/duty_cycle", pin);
if((fd = fopen(fName, "w")) ==
NULL) {
printf("Error: can't open pin
duty_cycle\n");
return false;
}
fprintf(fd, "%d\n",
duty_cycle);
fclose(fd);
|