Skip to content

Instantly share code, notes, and snippets.

@likersacademia
Last active August 20, 2018 06:27
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 likersacademia/713e7f3857dce4cd555de4de86b1a2cf to your computer and use it in GitHub Desktop.
Save likersacademia/713e7f3857dce4cd555de4de86b1a2cf to your computer and use it in GitHub Desktop.
//時計回りのモーターが、ボタンを押すと、反時計回りになるプログラム
#include <Servo.h>
#define motorPin 3
#define buttonPin 12
int buttonState = 0;
Servo myservo;
void setup() {
myservo.attach(motorPin,700,2300);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
Serial.println("Switch ON");
//時計回り(when 1450~700 µsec) 逆時計回り(when 1550~2300 µsec) 1500に近い方が回転がおそくなる
myservo.write(1600); //反時計回り
delay(100);
} else {
myservo.write(1400); //時計回り
delay(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment