Skip to content

Instantly share code, notes, and snippets.

@RoyBellingan
Created December 18, 2024 03:54
Show Gist options
  • Save RoyBellingan/000d5dbc64f6050d34578ccd6641f0aa to your computer and use it in GitHub Desktop.
Save RoyBellingan/000d5dbc64f6050d34578ccd6641f0aa to your computer and use it in GitHub Desktop.
pwm.c
//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