Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo mouth;
- Servo neck;
- const int buttonPin = 7;
- int buttonState;
- int mouthPos = -1;
- int lastButtonState = LOW;
- long lastDebounceTime= 0;
- long debounceDelay = 50;
- void setup() {
- mouth.attach(3);
- neck.attach(2);
- pinMode(buttonPin, INPUT);
- mouth.write(95);
- neck.write(75);
- }
- void loop() {
- int reading = digitalRead(buttonPin);
- if(reading != lastButtonState) {
- lastDebounceTime = millis();
- }
- if((millis() - lastDebounceTime) > debounceDelay) {
- if(reading != buttonState) {
- buttonState = reading;
- if(buttonState == HIGH) {
- toggleMouth();
- }
- }
- }
- lastButtonState = reading;
- int neckPot = analogRead(2);
- int neckPos = map(neckPot,0,1024,15,75);
- neck.write(neckPos);
- }
- void toggleMouth(){
- if(mouthPos == -1) {
- mouthPos = 1;
- mouth.write(75);
- } else {
- mouthPos = -1;
- mouth.write(95);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement