/* xavier salonga #300370523
firsr code to test all components
*/
#include <SoftwareSerial.h>
#include <Servo.h>
Servo servo;
int pos;
void setup() {
// set up all digitan input pins for the push buttons
pinMode(2, INPUT);// button a red button
pinMode(12, INPUT);// button b green button
pinMode(8, INPUT);// button c blue button
pinMode(7, INPUT);// button d yellow button
// set up all digital outputs for the led curcut
pinMode(5, OUTPUT);// amber led
pinMode(6, OUTPUT);//blue led
pinMode(10, OUTPUT);// green led
pinMode(9, OUTPUT);// red led
Serial.begin(9600); // Must be 9600
servo.attach(11);
}
const unsigned long T1 = 2000;
const unsigned long T2 = 4000;
unsigned long PT=0;
unsigned long PT2=0;
void loop() {
unsigned long CT= millis();
//turn off all the leds
digitalWrite(5, HIGH);// turn off amber led
digitalWrite(6, HIGH);// turn off blue led
digitalWrite(9, HIGH);// turn off green led
digitalWrite(10, HIGH);// turn off red led
// this section checks to see if all leds work
if (CT==1000){
digitalWrite(5, LOW);
}
if (CT==2000){
digitalWrite(6, LOW);
}
if (CT==3000){
digitalWrite(9, LOW);
}
if (CT==4000){
digitalWrite(10, LOW);
}
if(digitalRead(7)){
Serial.println("Button D Works:)");
}
if(digitalRead(8)){
Serial.println("Button C Works:)");
}
if(digitalRead(2)){
Serial.println("Button B Works:)");
}
if(digitalRead(12)){
Serial.println("Button A Works:)");
}
if(CT-PT==T1){
for(pos=0; pos <= 180; pos++){//sets the servo position form 9 to 100 degrees
servo.write(pos); // tells the servo to go to the possition from the for loop
}
PT=CT;
}
if(CT-PT2==T2){
for(pos=180; pos >= 0; pos--){//sets the servo position form 100 to 9 degrees
servo.write(pos);// tells the servo to go to the possition from the for loop
}
PT2=CT;
}
}