Skip to content

Instantly share code, notes, and snippets.

@protongt
Created January 2, 2016 17:11
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 protongt/a266731f8c2b8d0dfdca to your computer and use it in GitHub Desktop.
Save protongt/a266731f8c2b8d0dfdca to your computer and use it in GitHub Desktop.
Coding for controlling servo using cuteduino
/*
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