Skip to content

Instantly share code, notes, and snippets.

@locatw
Last active February 2, 2019 00:46
Show Gist options
  • Select an option

  • Save locatw/b26dfba72a2d7283bffef1a035655fc6 to your computer and use it in GitHub Desktop.

Select an option

Save locatw/b26dfba72a2d7283bffef1a035655fc6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <wiringPi/wiringPi.h>
int main()
{
if (wiringPiSetupGpio() == -1) {
std::cout << "cannot setup gpio." << std::endl;
return 1;
}
pinMode(18, PWM_OUTPUT);
pwmSetMode(PWM_MODE_MS);
pwmSetClock(400);
pwmSetRange(1024);
while (true) {
int num;
std::cin >> num;
if (num == -1) {
break;
}
pwmWrite(18, num);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment