#include <Arduino.h>
#include <Servo.h>
/*** Shane Farnsworth
Sudent # 300371791
Date: Feb 13, 2024
Midterm Prep Exercise 2 */
using namespace std;
////////////////////////////////////////////////////////////
// Declare all public constants within scope of program ////
const unsigned int BTN_A_RED = 2;
const unsigned int BTN_B_GREEN = 12;
const unsigned int BTN_C_BLUE = 8;
const unsigned int BTN_D_YELLOW =7;
const unsigned int LED_A_RED = 9;
const unsigned int LED_B_GREEN = 10;
const unsigned int LED_C_BLUE = 6;
const unsigned int LED_D_YELLOW = 5;
const unsigned int SERVO = 11;
///////////////////////////////////////////////////////////
bool check = false;
unsigned long lastMillis = 0;
unsigned long onTime = 120;
Servo C3PO; // Yes, it actually is a _
// Star Wars reference
void LEDon(bool, bool, bool, bool);
void setup() {
// Declare all push-button inputs within Arduino's pin configuration
pinMode(BTN_A_RED, INPUT_PULLUP);
pinMode(BTN_B_GREEN, INPUT);
pinMode(BTN_C_BLUE, INPUT);
pinMode(BTN_D_YELLOW, INPUT);
// Declare all LED outputs within Arduino's pin configuration
pinMode(LED_A_RED, OUTPUT);
pinMode(LED_B_GREEN, OUTPUT);
pinMode(LED_C_BLUE, OUTPUT);
pinMode(LED_D_YELLOW, OUTPUT);
attachInterrupt(digitalPinToInterrupt(BTN_A_RED), handleRED, RISING);
attachInterrupt(digitalPinToInterrupt(BTN_B_GREEN), handleGREEN, RISING);
attachInterrupt(digitalPinToInterrupt(BTN_C_BLUE), handleBLUE, RISING);
// Declare Servo's PWM for Arduino's pin configuration
C3PO.attach(SERVO);
// Initialize LED lights to start OFF (HIGH)
// as per LED circuit being active-low
LEDon(false, false, false, false);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
if (currentMillis - lastMillis >= onTime)
{
lastMillis = currentMillis;
}
}
void handleRED()
{
}
void LEDon(bool bRed, bool bGreen, bool bBlue, bool bYellow)
{
// I decided to use a function for switching state of LED's
// Just so I only have to write the code once, being more efficient
//
// PLEASE NOTE: I made the function turn on the LED when true was
// entered for bool parameter's in function call
// It just seemed "SIMPLER" to say 'TRUE' for LED to turn on
//
digitalWrite(LED_A_RED, !bRed);
digitalWrite(LED_B_GREEN, !bGreen);
digitalWrite(LED_C_BLUE, !bBlue);
digitalWrite(LED_D_YELLOW, !bYellow);
}