#include <Arduino.h>
#include <Servo.h>
/*Nakul Verma, Student # 12345
Code for Exercise 1, Problem 2 Rotate servo between 2° and 45°
Component list is as follows:
Pushbutton circuits that generate a logic high are connected to digital pins:
2 - Button A
12 - Button B
8 - Button C
7 - Button D
LEDS cicuits are on the following digital pins:
5 - Orange LED
6 - Blue LED
10 - Green LED
9 - Red LED
Servo control line is on digital pin 11
*/
Servo twisty; //declare servo as variable twisty
void setup() {
// put your setup code here, to run once:
//designate the LED pins as OUTPUTS
pinMode(5,OUTPUT); //Orange LED
pinMode(6,OUTPUT); //Blue LED
pinMode(9,OUTPUT); //Red LED
pinMode(10,OUTPUT); //Green LED
//designate pushbutton pins as INPUTS
pinMode(2,INPUT); //Button A
pinMode(7,INPUT); //Button D
pinMode(8,INPUT); //Button C
pinMode(12,INPUT); //Button B
//attach pin 11 as the servo control line
twisty.attach(11);
}
void loop() {
//start by turning off all the leds
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
//rotate servo to 2° (setting the servo position to 0° causes hardware mechanical stuttering)
//hold the 2° position for 300 ms
twisty.write(2);
delay(300);
//rotate servo to 45°
//hold the 45° position for 450ms
twisty.write(45);
delay(450);
}