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.

Tuesday, June 11, 2013

Dan | Stephen// The Final Countdown

Captain's Log, Stardate: 91048.43


Our project, Flushing Forests is designed to help put an end to excessive toilet paper use. We use a fairly simple input and feedback system to alert the user to when they use too much paper. The Arduino Uno reads the length of paper used each time a person pulls from it. This is done with a wheel that spins with the paper. Tabs on the wheel, presses a lever switch and number of clicks it makes corresponds to the number of squares used. Each attempt to pull paper, has a maximum amount allotted. Audio feedback is played for each square of paper, with an error sound each time they go over the limit. Through our research, we found that people will go for multiple pulls of paper for various reasons. To account for this, we allow multiple pulls of paper, but reduce the maximum limit by 1 for each consecutive pull, beginning with 6 squares, then down to 2 squares indefinitely.

#include "SimpleSDAudio.h"

/*
Authors: Dan Doan and Stephen Bader
Credits: Code heavily adapted from:


Description: Uses a piezo speaker, mouse click wheel, SD card shield, and lever switch to play audio based on 
             squares of toilet paper used.
*/

const int  buttonPin = 6;    // the pin that the pushbutton is attached to
const int speaker = 9;       // the pin that the LED is attached to


// Variables will change:
int clicks = 0;  //counter for the number of button presses
int sheets = 0;  //counter for number of sheets used
int sheetsMax = 6;  //sheetsmax sets the most amount of sheets you can use before the alarm goes off
int buttonState = 0;  //current state of the button
int lastButtonState = 0;  //previous state of the button
boolean pulled = false;  //Records if paper pull has happened
unsigned long pullTime; //Time since the last pull


void setup() {
  Serial.begin(9600);
  Serial.println("H E L L O W O R L D !");
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(speaker, OUTPUT);
  // initialize serial communication:
  
  SdPlay.setSDCSPin(10);
  SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_STEREO | SSDA_MODE_AUTOWORKER);
}

void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    pullTime = millis();  //Records when paper pulling starts
    pulled = true;  //Records if they start pulling paper
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      clicks++;
    } 
  }
  
  lastButtonState = buttonState;  //saves the current state as the last state for next run through the loop
 
  if(clicks == 3) {  //Convert number of clicks to sheets
    clicks = 0;
    sheets++;  //3 clicks = 1 sheet
    Serial.print("sheets:  ");
    Serial.println(sheets);
    
    //Selects the audio corresponding to the number of sheets used
    if (sheets == 1) {    
      SdPlay.setFile("1.wav"); 
    }
    if (sheets == 2) {    
      SdPlay.setFile("2.wav"); 
    }
    if (sheets == 3) {    
      SdPlay.setFile("3.wav"); 
    }
    if (sheets == 4) {    
      SdPlay.setFile("4.wav"); 
    }
    if (sheets == 5) {    
      SdPlay.setFile("5.wav"); 
    }
    if (sheets == 6) {    
      SdPlay.setFile("6.wav"); 
    }
    
    if (sheets > sheetsMax) {  // Anything over the max sheets gets an error sound
      Serial.println("STOP!");
      SdPlay.setFile("ERROR.wav"); 
    }
    
    SdPlay.play();
  } 
  
  //Tracks time between pulls
  if(pulled == true && millis() - pullTime >= 6000) {  // Checks if a pull has happened and lets 6 seconds pull
      pullTime = millis();
      pulled = false;
      clicks = 0;  // Resets clicks and sheets for the next pull
      sheets = 0; 
      if (sheetsMax > 2) {  //This stops sheetsMax from going lower than 2 sheets
        sheetsMax--;  //Decreases max allowed sheets for next pull
        Serial.print("sheetsMax is now: ");
        Serial.println(sheetsMax);
      }
  }
}




No comments:

Post a Comment