Last active
August 20, 2018 06:27
-
-
Save likersacademia/713e7f3857dce4cd555de4de86b1a2cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//時計回りのモーターが、ボタンを押すと、反時計回りになるプログラム | |
#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