#define NUM_RGB_LEDS 4
// Replace these with your actual pin assignments
#define RED_PIN_1 23
#define GREEN_PIN_1 22
#define BLUE_PIN_1 21
#define RED_PIN_2 19
#define GREEN_PIN_2 18
#define BLUE_PIN_2 5
#define RED_PIN_3 4
#define GREEN_PIN_3 2
#define BLUE_PIN_3 15
#define RED_PIN_4 27
#define GREEN_PIN_4 12
#define BLUE_PIN_4 14
const int potentiometerPin = 13; // Analog pin for the potentiometer
const int slideSwitchPin = 32; // Digital pin for the slide switch
void setup() {
Serial.begin(115200);
// Set RGB pins as OUTPUT
pinMode(RED_PIN_1, OUTPUT);
pinMode(GREEN_PIN_1, OUTPUT);
pinMode(BLUE_PIN_1, OUTPUT);
pinMode(RED_PIN_2, OUTPUT);
pinMode(GREEN_PIN_2, OUTPUT);
pinMode(BLUE_PIN_2, OUTPUT);
pinMode(RED_PIN_3, OUTPUT);
pinMode(GREEN_PIN_3, OUTPUT);
pinMode(BLUE_PIN_3, OUTPUT);
pinMode(RED_PIN_4, OUTPUT);
pinMode(GREEN_PIN_4, OUTPUT);
pinMode(BLUE_PIN_4, OUTPUT);
// Set slide switch pin as INPUT_PULLUP
pinMode(slideSwitchPin, INPUT_PULLUP);
}
void loop() {
// Read potentiometer values to set temperature
int potValue = analogRead(potentiometerPin);
float temperatureSetpoint = map(potValue, 0, 1023, 0, 50); // Map potentiometer values to temperature range
// Read slide switch state
int switchState = digitalRead(slideSwitchPin);
// Simulate washing machine operation for each machine
for (int machine = 0; machine < NUM_RGB_LEDS; machine++) {
operateWashingMachine(temperatureSetpoint, machine, switchState);
delay(100); // Simulated delay between machine updates
}
}
void operateWashingMachine(float temperatureSetpoint, int machine, int switchState) {
// Check temperature and update RGB lights based on machine number and switch state
switch (machine) {
case 0: // Machine 1 (Standard washing machine)
if (temperatureSetpoint >= 20.0 && temperatureSetpoint <= 30.0 && switchState == HIGH) {
setRGBColor(RED_PIN_1, GREEN_PIN_1, BLUE_PIN_1, 0, 255, 0); // Green light
} else {
setRGBColor(RED_PIN_1, GREEN_PIN_1, BLUE_PIN_1, 255, 0, 0); // Red light if conditions are not met
}
break;
case 1: // Machine 2 (Cold water washing machine)
if (temperatureSetpoint < 20.0) {
setRGBColor(RED_PIN_2, GREEN_PIN_2, BLUE_PIN_2, 0, 0, 255); // Blue light
} else {
setRGBColor(RED_PIN_2, GREEN_PIN_2, BLUE_PIN_2, 255, 0, 0); // Red light if conditions are not met
}
break;
case 2: // Machine 3 (Warm water washing machine)
if (temperatureSetpoint > 30.0 && temperatureSetpoint <= 40.0 && switchState == HIGH) {
setRGBColor(RED_PIN_3, GREEN_PIN_3, BLUE_PIN_3, 255, 255, 0); // Yellow light
} else {
setRGBColor(RED_PIN_3, GREEN_PIN_3, BLUE_PIN_3, 255, 0, 0); // Red light if conditions are not met
}
break;
case 3: // Machine 4 (Hot water washing machine)
if (temperatureSetpoint > 40.0) {
setRGBColor(RED_PIN_4, GREEN_PIN_4, BLUE_PIN_4, 255, 0, 0); // Red light
} else {
setRGBColor(RED_PIN_4, GREEN_PIN_4, BLUE_PIN_4, 0, 0, 255); // Red light if conditions are not met
}
break;
default:
break;
}
// Display temperature setpoint on Serial Monitor
Serial.print("Temperature Setpoint: ");
Serial.print(temperatureSetpoint);
Serial.println("°C");
// Display slide switch state on Serial Monitor
Serial.print("Slide Switch State: ");
Serial.println(switchState);
// Display RGB color on Serial Monitor
Serial.print("RGB Color: (");
Serial.print(getRedPin(machine));
Serial.print(", ");
Serial.print(getGreenPin(machine));
Serial.print(", ");
Serial.print(getBluePin(machine));
Serial.println(")");
delay(2000); // Simulated delay before the next iteration
}
void setRGBColor(int redPin, int greenPin, int bluePin, int red, int green, int blue) {
// Set RGB color for the specified machine
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
int getRedPin(int machine) {
switch (machine) {
case 0: return RED_PIN_1;
case 1: return RED_PIN_2;
case 2: return RED_PIN_3;
case 3: return RED_PIN_4;
default: return -1; // Invalid machine number
}
}
int getGreenPin(int machine) {
switch (machine) {
case 0: return GREEN_PIN_1;
case 1: return GREEN_PIN_2;
case 2: return GREEN_PIN_3;
case 3: return GREEN_PIN_4;
default: return -1; // Invalid machine number
}
}
int getBluePin(int machine) {
switch (machine) {
case 0: return BLUE_PIN_1;
case 1: return BLUE_PIN_2;
case 2: return BLUE_PIN_3;
case 3: return BLUE_PIN_4;
default: return -1; // Invalid machine number
}
}