// JOSEPH KONADU YEBOAH - 1704814716
// YUSSIF PENNIE - 1694713209
//Project name: Smart Analog Lighting Control System
int red = 9; // Declare a variable 'red' and assign it to digital pin 9
int yellow = 10; // Declare a variable 'yellow' and assign it to digital pin 10
int green = 11; // Declare a variable 'green' and assign it to digital pin 11
int blue = 12; // Declare a variable 'blue' and assign it to digital pin 12
void setup() {
Serial.begin(9600); // Initialize serial communication at a baud rate of 9600 bps
pinMode(red, OUTPUT); // Set pin 'red' as an output
pinMode(yellow, OUTPUT);// Set pin 'yellow' as an output
pinMode(green, OUTPUT); // Set pin 'green' as an output
pinMode(blue, OUTPUT); // Set pin 'blue' as an output
// Ensure all the pins are initially LOW (LEDs off)
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
void loop() {
if (analogRead(A0) > 1000) { // Read analog value from pin A0 and check if it is greater than 1000 (Y-axis max position)
Serial.println("TOP"); // Print "TOP" to the serial monitor
// Turn on the 'red' LED and turn all other LEDs off
digitalWrite(red, HIGH);
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
if (analogRead(A0) == 0) { // Read analog value from pin A0 and check if it is 0 (Y-axis min position)
Serial.println("BOTTOM"); // Print "BOTTOM" to the serial monitor
// Turn on the 'yellow' LED and turn all other LEDs off
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
if (analogRead(A1) > 1000) { // Read analog value from pin A1 and check if it is greater than 1000 (X-axis min position)
Serial.println("LEFT"); // Print "LEFT" to the serial monitor
// Turn on the 'green' LED and turn all other LEDs off
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, LOW);
}
if (analogRead(A1) == 0) { // Read analog value from pin A1 and check if it is 0 (X-axis max position)
Serial.println("RIGHT"); // Print "RIGHT" to the serial monitor
// Turn on the 'blue' LED and turn all other LEDs off
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
}
if (analogRead(A2) == 0) { // Read analog value from pin A2 and check if it is 0 (button pressed)
Serial.println("BUTTON PRESSED"); // Print "BUTTON PRESSED" to the serial monitor
// Turn on all LEDs
digitalWrite(red, HIGH);
digitalWrite(yellow, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
}
else {
Serial.println("**************"); // Print a separator line to the serial monitor
// Turn off all LEDs
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
delay(100); // Wait for 100 milliseconds before repeating the loop
}