As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Saturday, June 6, 2015

Tess & Jordan Final Code

Our code ended up being way more complicated than we thought it would be and took more than a few confusing sessions to complete. We had issues because we had a few actions happening inside of one continuous action which we were trying to use a while loop for. But, we used if statements instead which worked a lot better. Now, if someone gets up for more than 5 minutes during their period of sitting for 30 minutes, the timer will reset. Also, if someone sits down before their 5 minute break is up, the beep will reset and play a second beep. We've tested this code numerous times with success and now will start on the construction of our chair.

boolean sit;

boolean breaking;


//Reading integers from photocell
int photocellPin;
int photocellReading;
int sitThreshold;

// sit timer
long sitStart;
long sitEnd;
long sitLimit;


// break timer
long breakStart;
long breakEnd;
long breakLimit;


boolean firstBeep;
int firstBeepTime;

int beepWaitTime;

boolean secondBeep;
int secondBeepTime;

void setup() {
  Serial.begin(9600);
  sit = false;
  photocellPin = 0;
  sitThreshold = 600;
  sitLimit = 10000;
  
  breaking = false;
  breakLimit = 5000;
  
  
  firstBeep = false;
  firstBeepTime = 3000;
  
  beepWaitTime = 3000;
  
  secondBeep = false;
  secondBeepTime = 4000;
  pinMode(13, OUTPUT);
  Serial.println("Setup complete!");

}

void reset() {
  
  sit = false;
  breaking = false;
  
  firstBeep = false;
  secondBeep = false;
  
  sitStart = 0;
  sitEnd = 0; 
  
  breakStart = 0; 
  breakEnd = 0; 
  
 Serial.println("Resetting.");
}


void loop() { 
  
  photocellReading = analogRead(photocellPin);
  
  //sitting down on chair// 
  
  if (sit == false)  {
      if (photocellReading < sitThreshold) {
        sit = true;
        
        sitStart = millis();
        sitEnd = sitStart + sitLimit;
        Serial.println("SOMEONE IS SITTING!");
      }
  }
  //getting up for a break//
  
  if (sit && (millis() < sitEnd))  {
    if ((photocellReading >= sitThreshold) && !breaking) {
      breaking = true;
      breakStart = millis();
      breakEnd = breakStart + breakLimit;
      Serial.println("Breaking...");
    }
  }
   
   //up during break for longer than given break time//
   
    if (breaking && (millis() >= breakEnd)) {
      reset();
    }

  
   //person got up for a break but time ended before the sit limit and break time was up//
   
  if (sit && millis() < sitEnd && breaking && millis() >= breakEnd) {
    reset();
  }
  
  //first beep//
  
  if (sit && (millis() >= sitEnd) && !firstBeep) {
    firstBeep = true;
    tone(8, 300, firstBeepTime);
    Serial.println("First beep");
    delay(firstBeepTime + beepWaitTime);
    photocellReading = analogRead(photocellPin);
    if (photocellReading > sitThreshold) {
      reset();
    }
  }
  //second beep//
  
  if (sit && (millis() >= sitEnd) && firstBeep && !secondBeep) {
     secondBeep = true;
     tone(8, 400, secondBeepTime);
     Serial.println("Second beep");
     reset(); 
    }

  }

No comments:

Post a Comment