Skip to content

Instantly share code, notes, and snippets.

@aycabta
Created January 1, 2017 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aycabta/5c3149391d5c9429cd0a8a67625c9c24 to your computer and use it in GitHub Desktop.
Save aycabta/5c3149391d5c9429cd0a8a67625c9c24 to your computer and use it in GitHub Desktop.
all: test
test: test.o
gcc bcm2835-1.50/src/bcm2835.o test.o -o test
test.o: test.c
gcc -c -Ibcm2835-1.50/src/ test.c
clean:
rm test test.o
#include <bcm2835.h>
/* libbcm2835: http://www.airspayce.com/mikem/bcm2835/ */
#define PWM_CHANNEL 0
int main(int argc, char **argv)
{
if (!bcm2835_init())
return 1;
bcm2835_gpio_fsel(RPI_GPIO_P1_18, BCM2835_GPIO_FSEL_INPT);
bcm2835_pwm_set_mode(PWM_CHANNEL, 1, 1);
bcm2835_pwm_set_clock(1920);
bcm2835_pwm_set_range(PWM_CHANNEL, 200);
int angle = 0;
if (argc > 1) {
angle = atoi(argv[1]);
}
bcm2835_pwm_set_data(PWM_CHANNEL, angle);
bcm2835_close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment