#include <Servo.h>
/*
Ayoub naoui:
14-Feb-2024
Arduino Midterm Prep Exercises
Excersize 1 2 and 3
*/
/*Sevo name is servoMotor*/
Servo wiggly;
/*Keeps track of the position in degrees of the Servo Motor*/
//int position = 0;
/*Used as a increment variable for excersize 2 and 3 */
//int count = 0;
void setup()
{
/*Declare all the LED(s) as OUTPUTS for Arduino*/
/*They are logical gates that send a electrical
to a device eg, a Led or Servo Motor used for all exersices 1 2 and 3*/
pinMode(5, OUTPUT); //IO pin for orange led
pinMode(6, OUTPUT); //IO pin for blue led
pinMode(9, OUTPUT); //IO pin for Red led
pinMode(10, OUTPUT);//IO pin for Green led
/*Declare all pushbuttons as outputs*/
pinMode(2, INPUT);
pinMode(12, INPUT);
pinMode(8, INPUT);
pinMode(7, INPUT);
/*Designate pin 11 as the Servo Motor PWM pin */
wiggly.attach(11);
/*setup the serial Monitro to test the push buttons
and other functionality*/
Serial.begin(9600);
}
void loop()
{
/*Place all my main code here to run repeatedly*/
/*Firstly start by turning all the leds off if yellow - pin7 button is pressed before hand*/
while(digitalRead(8)==HIGH)
{
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(1000);
}
/*Excersize 1a - Individually turn on all the leds or blink them*/
while(digitalRead(2)==HIGH) //while 2-Red button is pressed
{
digitalWrite(5, LOW);
delay(1500);
digitalWrite(5, HIGH);
delay(1500);
}
}