// SPEAKER int speakerPin = A0; int numTones1 = 3; int tones1[] = {1915, 1915, 1915, 1915}; int numTones2 = 3; int tones2[] = {1915, 1915, 1915, 1915}; // BUTTONS int inPin1 = 3; // Burner 1 int inPin2 = 5; // Burner 2 int inPin3 = 7; // Burner 3 int inPin4 = 9; // Burner 4 int inPin5 = 11; // Oven int inPin6 = 13; // Microwave // HEATERS int outPin1 = 2; // Burner 1 int outPin2 = 4; // Burner 2 int outPin3 = 6; // Burner 3 int outPin4 = 8; // Burner 4 int outPin5 = 10; // Oven int outPin6 = 12; // Microwave // VARIABLES int state1 = LOW; // the current state of the burner 1 pin int state2 = LOW; // the current state of the burner 2 pin int state3 = LOW; // the current state of the burner 3 pin int state4 = LOW; // the current state of the burner 4 pin int state5 = LOW; // the current state of the oven pin int state6 = LOW; // the current state of the microwave pin int reading1; // the current reading from the burner 1 input pin int reading2; // the current reading from the burner 2 input pin int reading3; // the current reading from the burner 3 input pin int reading4; // the current reading from the burner 4 input pin int reading5; // the current reading from the oven input pin int reading6; // the current reading from the microwave input pin int previous1 = LOW; // the previous reading from the burner 1 input pin int previous2 = LOW; // the previous reading from the burner 2 input pin int previous3 = LOW; // the previous reading from the burner 3 input pin int previous4 = LOW; // the previous reading from the burner 4 input pin int previous5 = LOW; // the previous reading from the oven input pin int previous6 = LOW; // the previous reading from the microwave input pin // the follow variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long time1 = 0; // the last time the output pin was toggled long time2 = 0; // the last time the output pin was toggled long time3 = 0; // the last time the output pin was toggled long time4 = 0; // the last time the output pin was toggled long time5 = 0; // the last time the output pin was toggled long time6 = 0; // the last time the output pin was toggled long debounce1 = 200; // the debounce time, increase if the output flickers long debounce2 = 200; // the debounce time, increase if the output flickers long debounce3 = 200; // the debounce time, increase if the output flickers long debounce4 = 200; // the debounce time, increase if the output flickers long debounce5 = 200; // the debounce time, increase if the output flickers long debounce6 = 200; // the debounce time, increase if the output flickers int count1 = 0; int count2 = 0; int count3 = 0; int count4 = 0; int count5 = 0; int count6 = 0; void setup() { pinMode(inPin1, INPUT_PULLUP); pinMode(outPin1, OUTPUT); pinMode(inPin2, INPUT_PULLUP); pinMode(outPin2, OUTPUT); pinMode(inPin3, INPUT_PULLUP); pinMode(outPin3, OUTPUT); pinMode(inPin4, INPUT_PULLUP); pinMode(outPin4, OUTPUT); pinMode(inPin5, INPUT_PULLUP); pinMode(outPin5, OUTPUT); pinMode(inPin6, INPUT_PULLUP); pinMode(outPin6, OUTPUT); pinMode(speakerPin, OUTPUT); } void loop() { reading1 = digitalRead(inPin1); // Burner 1 reading2 = digitalRead(inPin2); // Burner 2 reading3 = digitalRead(inPin3); // Burner 3 reading4 = digitalRead(inPin4); // Burner 4 reading5 = digitalRead(inPin5); // Oven reading6 = digitalRead(inPin6); // Microwave // if the input just went from LOW and HIGH and we've waited long enough // to ignore any noise on the circuit, toggle the output pin and remember // the time // Burner 1 if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce1) { if (state1 == HIGH) state1 = LOW; else state1 = HIGH; time1 = millis(); } // Burner 2 if (reading2 == HIGH && previous2 == LOW && millis() - time2 > debounce2) { if (state2 == HIGH) state2 = LOW; else state2 = HIGH; time2 = millis(); } // Burner 3 if (reading3 == HIGH && previous3 == LOW && millis() - time3 > debounce3) { if (state3 == HIGH) state3 = LOW; else state3 = HIGH; time3 = millis(); } // Burner 4 if (reading4 == HIGH && previous4 == LOW && millis() - time4 > debounce4) { if (state4 == HIGH) state4 = LOW; else state4 = HIGH; time4 = millis(); } // Oven if (reading5 == HIGH && previous5 == LOW && millis() - time5 > debounce5) { if (state5 == HIGH) state5 = LOW; else state5 = HIGH; time5 = millis(); } // Microwave if (reading6 == HIGH && previous6 == LOW && millis() - time6 > debounce6) { if (state6 == HIGH) state6 = LOW; else state6 = HIGH; time6 = millis(); } delay(1000) ; // pause 1 second // BURNER 1 if (state1 == HIGH) count1 = (count1 + 1); if (count1 == 15) state1 = LOW; if (count1 == 15) count1 = 0; if (state1 == LOW) count1 = 0; // BURNER 2 if (state2 == HIGH) count2 = (count2 + 1); if (count2 == 15) state2 = LOW; if (count2 == 15) count2 = 0; if (state2 == LOW) count2 = 0; // BURNER 3 if (state3 == HIGH) count3 = (count3 + 1); if (count3 == 15) state3 = LOW; if (count3 == 15) count3 = 0; if (state3 == LOW) count3 = 0; // BURNER 4 if (state4 == HIGH) count4 = (count4 + 1); if (count4 == 15) state4 = LOW; if (count4 == 15) count4 = 0; if (state4 == LOW) count4 = 0; // OVEN if (state5 == HIGH) count5 = (count5 + 1); if (count5 == 20) state5 = LOW; // SOUND WHEN FINISHED if (count5 == 20) for (int i = 0; i < numTones1; i++) { tone(speakerPin, tones2[i]); } noTone(speakerPin); if (count5 == 20) count5 = 0; if (state5 == LOW) count5 = 0; // MICROWAVE if (state6 == HIGH) count6 = (count6 + 1); if (count6 == 10) state6 = LOW; // SOUND WHEN FINISHED if (count6 == 10) for (int i = 0; i < numTones1; i++) { tone(speakerPin, tones1[i]); delay(1000); noTone(speakerPin); delay(1000); } noTone(speakerPin); if (count6 == 10) count6 = 0; if (state6 == LOW) count6 = 0; // DIAGNOSTICS ONLY Serial.println(millis()); Serial.println(count1); // FIRST COUNTER Serial.println(count2); // SECOND COUNTER Serial.println(state1); Serial.println(state2); digitalWrite(outPin1, state1); // Burner 1 digitalWrite(outPin2, state2); // Burner 2 digitalWrite(outPin3, state3); // Burner 3 digitalWrite(outPin4, state4); // Burner 4 digitalWrite(outPin5, state5); // Oven digitalWrite(outPin6, state6); // Microwave previous1 = reading1; // Burner 1 previous2 = reading2; // Burner 2 previous3 = reading3; // Burner 3 previous4 = reading4; // burner 4 previous5 = reading5; // Oven previous6 = reading6; // Microwave }