Servo Motor Control With Touch Sensor

      

            CODE

#include <Servo.h>

#include <stdio.h>

#include <stdlib.h>


Servo top;

Servo bot;


const int button = 2;

const int led =7;


int xval = 0;

int yval = 0;

int pos = 0;

int pos1 = 0;

int readv = 0;

int ledflag=0;



void setup() {

  pinMode(button, INPUT);

  top.attach(9);

  bot.attach(10);

  pinMode(button,INPUT);

  Serial.begin(9600);

  digitalWrite(led,LOW);


}


void loop() {

  if (digitalRead(button)==HIGH){

    if (ledflag==0) {

      ledflag=1;

      bot.write(160);

      delay(100);

      top.write(180);

      delay(800);

      digitalWrite(led, HIGH);

  }

    else {

      ledflag=0;

      digitalWrite(led, LOW);

      delay(500);

      bot.write(0);

      delay(50);

      top.write(30);

    }

    delay(1000);

  

  }

}


Post a Comment

Previous Post Next Post

Contact Form