C++ サーボモータを回す
PWMのヂューティーを変化させると、サーボーモータの角度が変わることを確認しよう
#include <wiringPi.h>
#include <iostream>
#include <softPwm.h>
using namespace std;
int PORT = 18;
void set_angle(int angle) {
	double duty;
	duty = angle / 9.8 + 5;
	softPwmWrite(PORT, int(duty));
}
int main() {
	if (wiringPiSetupGpio() == -1) {
		cout << "Gpio setup error\n";
		exit(EXIT_FAILURE);
	}
	softPwmCreate(PORT, 0, 100);
	
	for(int deg = 0; deg<=180 ; deg+= 10) {
		cout << "deg=" << deg << endl;
		set_angle(deg);
		delay(1000);
	}
}
						このサーボモータの角度の精度はそれほどでもないのです