Projects/Pantry

/* PANTRY LIGHT CONTROL by Kenneth Burgener (2014)

int blink_led = 11;   // on board LED int blink_counter = 0;

int relay_pin = 21;   // relay control pin int relay_counter = 0;

int fade_led = 12;    // the pin that the fade LED is attached to int brightness = 0;    // how bright the LED is int fadeAmount = 10;    // how many points to fade the LED by

int switch_pin = 20;  // pin for door input switch int switch_state = false; // if switch is on or off int switch_count = 0; int switch_val = HIGH;   // variable for input pin value int switch_val_last = HIGH;   // variable for input pin's previous value int switch_debounce = 0; // variable for debounce int switch_safety = false; int switch_off_delay = false;

int SECONDS = 10; // 10 * 100 ms delay int MINUTES = 60 * SECONDS; // 10 * 100 ms delay

void setup { pinMode(blink_led, OUTPUT);

pinMode(fade_led, OUTPUT);

pinMode(relay_pin, OUTPUT); digitalWrite(relay_pin, LOW);

pinMode(switch_pin, INPUT); digitalWrite(switch_pin, HIGH); // turn on pullup resistors }

void loop { /** SWITCH **/ /** SWITCH **/ /** SWITCH **/

// read switch state if (switch_debounce == 0) { switch_val_last = switch_val; switch_val = digitalRead(switch_pin); if (switch_val != switch_val_last) { switch_debounce = 5; }   if (switch_val == LOW) { digitalWrite(blink_led, HIGH); } else { digitalWrite(blink_led, LOW); } } else { switch_debounce--; }

/** RELAY **/ /** RELAY **/ /** RELAY **/

// of switch state change if (switch_debounce != 0 && switch_val != switch_val_last) { if (switch_val == LOW) { // switch on      switch_state = true; switch_count = 0; } else { // switch off switch_state = false; switch_safety = false; if (switch_safety == false) { switch_off_delay = true; }     switch_count = 0; } }

// switch on state and safety if (switch_state == true && switch_safety == false) { switch_count++; if (switch_count == 1) { digitalWrite(relay_pin, HIGH); }   if (switch_count == 300 * SECONDS) { // 5 MINUTES WARNING // warning off digitalWrite(relay_pin, LOW); }   if (switch_count == 301 * SECONDS) { // 5 MINUTE WARNING // warning on     digitalWrite(relay_pin, HIGH); }   if (switch_count == 330 * SECONDS) { // 5 MINUTE 30 SECOND SAFETY SHUTOFF // safety off digitalWrite(relay_pin, LOW); switch_state = false; switch_count = 0; switch_safety = true; } }  // reset safety if (switch_safety == true && switch_val == HIGH) { // switch off switch_safety = false; switch_count = 0; }

// switch off state and delay if (switch_state == false && switch_off_delay == true) { switch_count++; if (switch_count == 10 * SECONDS) { // 10 SECOND WARNING // warning off digitalWrite(relay_pin, LOW); }   if (switch_count == 11 * SECONDS) { // 10 SECOND WARNING // warning on     digitalWrite(relay_pin, HIGH); }   if (switch_count == 15 * SECONDS) { // 15 SECOND SHUTOFF digitalWrite(relay_pin, LOW); switch_count = 0; switch_off_delay = false; } }

/** BLINK LED **/ /** BLINK LED **/ /** BLINK LED **/ /* blink_counter++; if (blink_counter >= 4 * SECONDS) { blink_counter = 0; } if (blink_counter == 0) { digitalWrite(blink_led, HIGH); } if (blink_counter == 2 * SECONDS) { digitalWrite(blink_led, LOW); }

/** FADE LED **/ /** FADE LED **/ /** FADE LED **/

// set the brightness analogWrite(fade_led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 150) { fadeAmount = -fadeAmount ; }

/** LOOP DELAY **/ /** LOOP DELAY **/ /** LOOP DELAY **/ // wait for 100 milliseconds per cycle delay(100); }

%temp%\build3678427800310146579.tmp\sketch_mar09b.cpp void setup; void loop;
 * 1) line 1 "sketch_mar09b.ino"
 * 2) include "Arduino.h"
 * 1) line 1