Making Things Interactive

February 4, 2008

toilet seat

Filed under: 4: Counting Sensor Input,Nadeem Haidary — nhaidary @ 12:52 pm
Tags: , ,

After originally planning on doing something with push pins, a little group brainstorming lead me to this idea: a toilet seat that tells you how many people have sat on it. A switch embedded in the seat counts, while three LED’s display the number to each new sitter by blinking each digit. Red is the hundreds place, green is tens, and blue is ones, so the video shows the 439th toilet user. The device shows how close we all really are in a very neutral way, its up to you to find it unsettling or not. I can’t figure out the source code formatting, if anyone can help me out!

/*
* Toilet seat counter
* by Nadeem Haidary
*/

int switchPin = 2; // Switch connected to digital pin 2
int onesPin = 12; // Led that shows one’s place
int tensPin = 11; // Led that shows ten’s place
int hundredsPin = 10; // Led that shows hundred’s place
int buttonState; // variable to hold the last button state
int val; // variable for reading the pin status

// counts how many people have sat on the toilet seat
// these are random starting numbers
int onesCounter = 6;
int tensCounter = 3;
int hundredsCounter = 4;

//—————————————————————-

void setup() {
pinMode(onesPin, OUTPUT); // Set the LED pin as output
pinMode(switchPin, INPUT); // Set the switch pin as input

Serial.begin(9600); // Set up serial communication at 9600bps
buttonState = digitalRead(switchPin); // read the initial state
}

//—————————————————————-

void loop(){
val = digitalRead(switchPin); // read input value and store it in val

if (val != buttonState) {
if (val == LOW) { // check if the button is pressed

//COUNTER
//counts each digit and resets each to zero after 9
if (onesCounter == 9) {
onesCounter = 0;
if (tensCounter == 9) {
tensCounter = 0;
if (hundredsCounter == 9) {
hundredsCounter == 0;
}
else{
hundredsCounter++;
}
}
else {
tensCounter++;
}
}
else{
onesCounter++;
}

// BLINK DIGITS
// blink hundreds digit (red LED)
for (int i = 0; i < hundredsCounter; i++) { digitalWrite(hundredsPin, HIGH); // turn LED on delay (500); digitalWrite(hundredsPin, LOW); // turn LED off delay (500); } // blink tens digit (green LED) for (int i = 0; i < tensCounter; i++) { digitalWrite(tensPin, HIGH); // turn LED on delay (500); digitalWrite(tensPin, LOW); // turn LED off delay (500); } // blink ones digit (blue LED) for (int i = 0; i < onesCounter; i++) { digitalWrite(onesPin, HIGH); // turn LED on delay (500); digitalWrite(onesPin, LOW); // turn LED off delay (500); } } } buttonState = val; // save the new state in our variable } [/sourcecode]

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: