Monday, November 21, 2016

Arduino Reflex Test Code


#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int but = 7;
int buttonState = 0;
long ran = 0;
int beginTime = 0;
int delTime = 0;
int currTime = 0;
void setup() {
  pinMode(but, INPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
}

void loop() {
beginTime = millis();
buttonState = digitalRead(but);

 myservo.write(88);
  if(buttonState == HIGH)
  {
  tone(3, 2000, 300);
 
  delay(1000);
 
  ran = random(2000, 5000);

 delay(ran);



  myservo.write(150);

  delay(1000);
  tone(3, 3000, 300);
 
  }
 
 else
 {
  myservo.write(88);
 }

}

No comments:

Post a Comment