PComp project of my own volition (and past documentation)

Quick catch up: Last week we had to design a fantasy device. Mine is a weather controlling device (which I built a control panel for out of clay, newspaper, cardboard, old vcr parts, hot glue, and acrylic paint).

The front dials control what type of weather, and the intensity of that weather. The color gradient represents the temperature controller (approximate temperature range). The vertical wheel on the right controls the radius of the storm in miles, and the left vertical wheel controls how long from now the weather is slated to start. In the middle is the power (commit) button, and when you activate the machine lights up.

The PComp lab for this week involves building circuits and figuring out how to use the multimeter, but I have yet to visit Radio Shack so I am lacking a key piece. Instead I came upon a realization the other night / morning that I want to implement.

My room is ridiculously dark when the lights are off. I have no windows except a tiny one that leads out to the hallway, and I have mostly covered that with cardboard in the hopes of making my little fan more effective (so far it is not working, but hopefully it will be cold soon). I have also gotten very adept at turning off and ignoring any audible alarms I set for myself, which results in sleeping until 11 or so every day. I need to have a light alarm, such that when the alarm goes off, my lights in my room come on.

I am not yet ready to tap into my wall and start piecing it together that way, so instead I decided to build a proof of concept using a few LEDs and my Arduino.

One of the things that the fantasy device project brought up was the design of the control scheme for a set object. The controls are what allow a user and the machine to speak, and just as in conversation it is important that both parties understand each other.

My proof of concept light alarm functions as follows:

The user presses the close button, which both turns on the row of LEDs one at a time (one lit up for each press up to five, and then it resets back to zero), it also delays the alarm 1 second for each light that is on.

Once the back button is pressed, all of the LEDs in the row turn off, and the machine waits one second per LED that was lit up. It then turns on the larger LED (my room light). If the back button is pressed again, the light goes off and resets the alarm. Until the light is turned off, it is also impossible to set a new alarm even by pushing the front button.

Here is what my code looks like:

const int clockSetPin = 13;
const int lightPin1 = 12;
const int lightPin2 = 11;
const int lightPin3 = 10;
const int lightPin4 = 9;
const int lightPin5 = 8;

const int alarmStartPin = 4;
const int alarmLightPin = 2;

int clockSetSwitch = LOW;
int lastclockSetSwitch = LOW;
int light1 = LOW;
int light2 = LOW;
int light3 = LOW;
int light4 = LOW;
int light5 = LOW;

int alarmStart = LOW;
int lastAlarmStart = LOW;
int alarmLight = LOW;

int counter = 0;

boolean alarmwentoff = false;

void setup(){
  pinMode(clockSetPin, INPUT);
  pinMode(lightPin1, OUTPUT);
  pinMode(lightPin2, OUTPUT);
  pinMode(lightPin3, OUTPUT);
  pinMode(lightPin4, OUTPUT);
  pinMode(lightPin5, OUTPUT);

  pinMode(alarmStartPin, INPUT);
  pinMode(alarmLightPin, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  //digital inputs from the switches
  clockSetSwitch = digitalRead(clockSetPin);
  alarmStart = digitalRead(alarmStartPin);

  //if button is pushed, add to the counter
  if ((clockSetSwitch != lastclockSetSwitch) && (clockSetSwitch == LOW)){
    if (alarmwentoff == true){
      counter = 0;
    }
    else if (counter < 5){
      counter++;
    }
    else{
      counter = 0;
    }
  }
  //print out what counter is
  Serial.println(counter);

  lastclockSetSwitch = clockSetSwitch;

  //the counter turns on the lights to let you know how long before the alarm goes off
  if (counter == 1){
    digitalWrite(lightPin1, HIGH);
  }
  else if (counter == 2){
    digitalWrite(lightPin1, HIGH);
    digitalWrite(lightPin2, HIGH);
  }
  else if (counter == 3){
    digitalWrite(lightPin1, HIGH);
    digitalWrite(lightPin2, HIGH);
    digitalWrite(lightPin3, HIGH);
  }
  else if (counter == 4){
    digitalWrite(lightPin1, HIGH);
    digitalWrite(lightPin2, HIGH);
    digitalWrite(lightPin3, HIGH);
    digitalWrite(lightPin4, HIGH);
  }
  else if (counter == 5){
    digitalWrite(lightPin1, HIGH);
    digitalWrite(lightPin2, HIGH);
    digitalWrite(lightPin3, HIGH);
    digitalWrite(lightPin4, HIGH);
    digitalWrite(lightPin5, HIGH);
  }
  else{
    digitalWrite(lightPin1, LOW);
    digitalWrite(lightPin2, LOW);
    digitalWrite(lightPin3, LOW);
    digitalWrite(lightPin4, LOW);
    digitalWrite(lightPin5, LOW);
  }

  /*if the button is pushed and the alarm has not yet gone off, turn off all the lights
   then delay for 1 second times the amount of lights that were on
   and after the delay, turn on the alarm light*/

  if ((alarmStart != lastAlarmStart) && (alarmStart == LOW)){
    if (alarmwentoff == false){
      digitalWrite(lightPin1, LOW);
      digitalWrite(lightPin2, LOW);
      digitalWrite(lightPin3, LOW);
      digitalWrite(lightPin4, LOW);
      digitalWrite(lightPin5, LOW);
      Serial.println("AlarmStarted");
      delay(1000 * counter);
      digitalWrite(alarmLightPin, HIGH);
      Serial.println("Wake up!");
      counter = 0;
      alarmwentoff = true;
    }
    else if (alarmwentoff == true){        //if the alarm has gone off and the button was pressed
      digitalWrite(alarmLightPin, LOW);     //turn off the light and reset the alarm
      Serial.println("turned off!");
      alarmwentoff = false;
    }
  }

  lastAlarmStart = alarmStart;

}

and here is the video:
Prototype Light Alarm

Hopefully soon I will be able to implement this in
my room actually, and will begin waking up early!
This entry was posted in Physical Computing. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>