// Define pins for candles and input
int candles[] = {2, 3, 4, 5, 6, 7, 8, 12};
//#define inPin 13 // Define the pin for the push button
int val=13;
int yom = 0; // Counter for candles
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud rate
// Set up pin modes
pinMode(val, INPUT); // Set the push button pin as input
for (int i = 0; i < 8; i++) {
pinMode(candles[i], OUTPUT); // Set all candle pins as output
}
// Set RGB "shamas" LED pins as output
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0); // Read temperature sensor value
Serial.println(sensorValue); // Print the sensor value to the serial monitor
// Heat sensing logic to increment yom
if (sensorValue > 50) { // Adjust this threshold as needed
yom += 1;
delay(1500); // Delay to debounce and allow time for heat to dissipate
}
// Change RGB LED colors based on yom
if (yom > 0) {
analogWrite(9, random(100, 255)); // Random red intensity
analogWrite(10, random(100, 255)); // Random green intensity
analogWrite(11, random(100, 255)); // Random blue intensity
delay(100); // Small delay for flickering effect
} else {
analogWrite(9, 255); // Default color when no candles are lit
analogWrite(10, 255);
analogWrite(11, 255);
}
// Read push button input
int val = digitalRead(13); // Check if the button is pressed
if (val == HIGH) { // If button is pressed
yom += 1; // Increment yom
delay(500); // Debounce delay
if (yom > 8) { // Reset yom if it exceeds the number of candles
yom = 0;
}
}
// Control candles based on yom value
for (int i = 0; i < 8; i++) {
if (yom > i) {
digitalWrite(candles[i], HIGH); // Light candle
} else {
digitalWrite(candles[i], LOW); // Turn off candle
}
}
// Turn off all candles if yom is 0
if (yom == 0) {
for (int i = 0; i < 8; i++) {
digitalWrite(candles[i], LOW);
}
}
}