Created
January 2, 2016 17:11
-
-
Save protongt/a266731f8c2b8d0dfdca to your computer and use it in GitHub Desktop.
Coding for controlling servo using cuteduino
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
/* | |
Project Name : Servo control | |
Board : Cuteduino | |
Programmer : Eawan | |
9W2NFE.blogspot.com | |
~MechaMotion~ | |
Menggunakan touch sensor activation | |
Menggunakan servo sebagai end effector | |
servo 1 = digital pin 0 | |
*/ | |
#include <SimpleServo.h> | |
int buttonPin = 2; // touch sensor pin assign | |
boolean currentState = LOW;//storage for current button state | |
boolean lastState = LOW;//storage for last button state | |
boolean ledState = LOW;//storage for the current state of the LED (off/on) | |
SimpleServo Servo1; // servo name assign | |
void setup(){ | |
pinMode(buttonPin, INPUT);//this time we will set the pin as INPUT | |
Servo1.attach(0); // servo pin on digital pin 0 | |
Servo1.write(0); // servo default position 0 degrees | |
} | |
void loop(){ | |
currentState = digitalRead(buttonPin); | |
if (currentState == HIGH && lastState == LOW){ //if button has just been pressed | |
delay(1); //crude form of button debouncing | |
//toggle the state of the button status | |
if (ledState == HIGH){ | |
delay (500); //delay 0.5 sec | |
Servo1.write(0); //servo pos 1 | |
delay(1000); //delay 1 sec | |
ledState = LOW; | |
} | |
else { | |
delay (500); //delay 0.5 sec | |
Servo1.write(90); //servo pos 2 | |
delay(1000); //delay 1 sec | |
ledState = HIGH; | |
} | |
} | |
lastState = currentState; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment