Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ボタンを押すと、モーターが回るプログラム
- #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() {
- if (digitalRead(buttonPin) == HIGH){
- buttonState++;
- if(buttonState >1) buttonState = 0;
- delay(300);
- }
- if (buttonState == 1) {
- Serial.println("Switch ON");
- //時計回り(when 1450~700 µsec) 逆時計回り(when 1550~2300 µsec) 1500に近い方が回転がおそくなる
- myservo.write(1400); //時計回り
- delay(100);
- } else {
- myservo.write(1500); //stop
- delay(100);
- }
- }
Add Comment
Please, Sign In to add comment