//ENGR 1190 - Jan 31, 2022 In-class exercise
#include <Servo.h>
#include <Arduino.h>
int button_a = 13; //push button logic for Amber LED
int led_Amber = 5; // LED connected to PIN 5 of board for Amber LED
int button_b = 12; //push button logic for Blue LED
int led_Blue = 6; // LED connected to PIN 6 of board for Amber LED
int button_c = 8; //push button logic for Red LED
int led_Red = 9; // LED connected to PIN 9 of board for Amber LED
int button_d = 7; //push button logic for Green LED
int led_Green = 10; // LED connected to PIN 10 of board for Amber LED
Servo angle; //declare servo
void setup() {
// put your setup code here, to run once:
pinMode(button_a, INPUT); //button pin as Input
pinMode(led_Amber, OUTPUT);
pinMode(button_b, INPUT); //button pin as Input
pinMode(led_Blue, OUTPUT);
pinMode(button_c, INPUT); //button pin as Input
pinMode(led_Red, OUTPUT);
pinMode(button_d, INPUT); //button pin as Input
pinMode(led_Green, OUTPUT);
angle.attach(11); //set up servo to pin 11
Serial.begin(9600); //setting up serial monitor
Serial.println("Great Job, Sarah!\n");
}
void loop() {
// put your main code here, to run repeatedly:
delay(700); //keep all LEDs off for 700ms
digitalWrite(led_Amber, LOW);
digitalWrite(led_Blue, LOW);
digitalWrite(led_Red, LOW);
digitalWrite(led_Green, LOW);
//turn on pin is LOW, blind is HIGH
delay(700); //turn on LED on for 300 ms
digitalWrite(led_Amber, HIGH);
digitalWrite(led_Blue, HIGH);
digitalWrite(led_Red, HIGH);
digitalWrite(led_Green, HIGH);
//angle.write(90);
//clock wise 45 degrees
for (int pos = 90; pos <= 135; pos += 1) { // goes from 0 degrees to 45 degrees
// in steps of 1 degree (slowly rotating)
angle.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 135; pos >= 90; pos -= 1) { // goes from 45 degrees to 0 degrees
angle.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
//counter clock wise 45 degrees
for (int pos = 90; pos >= 45; pos -= 1) { // goes from 45 degrees to 0 degrees
angle.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
for (int pos = 45; pos <= 90; pos += 1) { // goes from 0 degrees to 45 degrees
// in steps of 1 degree (slowly rotating)
angle.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}