Created
December 18, 2024 03:54
-
-
Save RoyBellingan/000d5dbc64f6050d34578ccd6641f0aa to your computer and use it in GitHub Desktop.
pwm.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//gcc pwm.c -lwiringPi -o pwm | |
#include <wiringPi.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
int main (int argc, char *argv[]){ | |
if (argc != 4) { | |
printf("Usage: %s <pin> <pwmClockDivisor> <pwmDutyCycle>\n", argv[0]); | |
return 1; | |
} | |
int pin = atoi(argv[1]); | |
int pwmClockDivisor = atoi(argv[2]); | |
int pwmDutyCycle = atoi(argv[3]); | |
printf ("Raspberry Pi wiringPi PWM test program\n") ; | |
if (wiringPiSetup () == -1) | |
exit (1) ; | |
pinMode (pin, PWM_OUTPUT) ; | |
pwmSetClock(pwmClockDivisor); | |
pwmWrite (pin, pwmDutyCycle) ; | |
return 0 ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment