I would like to add a small pushbutton to my existing code that basically when pressed will turn on both my servo and led lights and when pressed again will shut them off. i am using a brick shield v4 and plugging the buckled cable into the A0 port on the side of the shield. Here are the links to the pushbutton and shield i am using as well as the existing code which i have working correctly.
http://www.trossenrobotics.com/store/p/6365-Electronic-Brick-Shield-V4.aspx
http://www.trossenrobotics.com/store/p/6359-Electronic-Brick-Mini-Push-Button.aspx
#include <Servo.h> //include the servo libary - a bunch of code for a host of servo instructions y9ou can use and don't have to develop yourself
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int delay1 = 0; // variable to store the delay between servo arm's movement info
int ledPin = 13; // LED connected to digital pin 13
long randOn = 0; // Initialize a variable for the ON time
long randOff = 0; // Initialize a variable for the OFF time
void setup()
{
myservo.attach(9); // attaches pin 9 of the micro controller to the servo object - the servo's "control wire"
randomSeed (analogRead (0)); // randomize
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
pos=random(65,115); // ramdomly set the servo arm postion between 65 & 115 degrees. "90" is "straight ahead"
delay1=random(50, 500); // randomly set delay between servo movement between 50 and 500 milliseconds
myservo.write(pos); // tell servo to go to position specified by variable ‘pos’ value
delay(delay1); // waits randomly between 50ms and 500 ms between servo movements
randOn = random (100, 1200); // generate ON time between 0.1 and 1.2 seconds
randOff = random (200, 900); // generate OFF time between 0.2 and 0.9 seconds
digitalWrite(ledPin, HIGH); // sets the LED on
delay(randOn); // waits for a random time while ON
digitalWrite(ledPin, LOW); // sets the LED off
delay(randOff); // waits for a random time while OFF