diff --git a/arduino/ServoSetHanzo4_1/ServoSetHanzo4_1.ino b/arduino/ServoSetHanzo4_1/ServoSetHanzo4_1.ino new file mode 100644 index 0000000..03afff2 --- /dev/null +++ b/arduino/ServoSetHanzo4_1/ServoSetHanzo4_1.ino @@ -0,0 +1,123 @@ +#include + +// Servo : SC-1267SG +unsigned int steeringServoCenter = 1820; //us +unsigned int steeringServoMin = (steeringServoCenter-780); //us +unsigned int steeringServoMax = (steeringServoCenter+780); //us + +// Servo : SC-0352 +unsigned int lanceServoCenter = 1560; //us +unsigned int lanceServoMin = (lanceServoCenter-780); //us +unsigned int lanceServoMax = (lanceServoCenter+780); //us + +unsigned char rotPin = 2; + +unsigned char numSensors = 8; +unsigned char sensorPin[] = {19,18,17,16,15,14,13,12}; //右端から順番に左端へ + +unsigned char steeringServoPin = 9; +unsigned char lanceServoPin = 10; + +volatile unsigned long distance = 0; + +Servo lanceServo; +Servo steeringServo; + +/* ステアリングを中央からa[度]だけ動かす + <- - 0 + -> + || + || + []---{}---[] + / .\ +*/ +int steering(int a){ + steeringServo.write(90 + a); + return (steeringServo.read() - 90); +} + +/* ランスを中央からa[度]だけ動かす + <- - 0 + -> + / .\ + / | \ + []+--{}--+[] +*/ +int lance(int a){ + lanceServo.write(90 - a); + return (90 - a); +} + +/* センサーのアレイの初期化 */ +void sensorInit(){ + for(int i=0; i100){ + i = 0; + Serial.print(distance); + Serial.print('\t'); + for(int i=0; i