Sunday, September 21, 2008
Blog Move
True to the name of this blog, I've set up a more permanent one at http://itp.nyu.edu/~zf213/blog/. I'll be posting there from now on, so that's where you should go!
Wednesday, September 17, 2008
Instant Hair Dye Applet
Yes indeed, it's a little applet in Processing that messes with this guy's hair color and gives you a thumbs-up and thumbs-down sign to let you know how he feels about it. Reload the page for new colors. This was completed in partnership with Vitaliy. Thanks Vitaliy!
Tuesday, September 16, 2008
Some Digital Devices!
The following digital devices were observed on Monday afternoon on a walk to Union Squiare with the two Tims. We purposely left out MP3 players and cellphones, else we wouldn't make it down the block.
Time Seen,
Purpose,
Average time for an interaction.
3:34 – Crosswalk Sign
– Waverly Place and Broadway
- To time and signal to pedestrians when it is safe for them to cross the street
- 0 to 60 seconds
3:38 – Bus MetroCard machine
- Waverly Place and Broadway
- To check and debit credits from a rider's account and signal to the
driver that they're qualified to ride
- About 5 seconds
3:39 – Electric Wheelchair
– Waverly Place and Broadway
- To provide personal locomotion without the use of legs
- Ongoing
3:41 – PS3 + X360 System and Controller
– GameStop on Broadway b/w Waverly Place and 8th Street
- To simulate the visual feedback of a football game depending on input
from a game controller
- 4 to 5 hours?
3:41 – Credit Card Swiper
– Same Location
- To identify and then access and debit money from a bank account, or
to access and place a charge against a credit card
- 10 to 15 seconds
3:42 – Security Monitor
– Same Location
- To monitor and let shoppers know that they can be seen
- Instant
3:43 – UPC Scanner
- Same Location
- To keep track of outgoing products from the store's stock as they're
sold to customers
- 1 to2 seconds
3:45 – Digital Watch
– 8th Street and Broadway
-To measure time
-1 to 2 seconds
3:47 – Security Scanner
– Broadway b/w 8th St. and 9th St.
- To notify staff when a piece of inventory leaves the store without
first going through the checkout process
- Instantaneous
3:51 – Digital Camera
- Broadway b/w 8th St. and 9th St.
-To record light waves in digital media
-5 to 10 seconds
3:51 – ATM
– HSBC Broadway b/w 8th St. and 9th St.
- To debit a user's bank account and dispense cash by that amount
-30 seconds to 1 minute
3:53 – Digital Bus Sign
- Broadway and 9th St.
-To inform riders which route a bus is currently driving
-1-2 seconds
3:55 – Personal Computer (screen, keyboard)
– Chase Bank on Broadway and 10th St.
- To take in banking information from the banker and display necessary
client details
- Ongoing
3:56 – Traffic Light
- Broadway and 10th St.
- To control the flow of cars and other vehicle traffic, to signal when
it's safe to accelerate and when it's necessary to stop
- 0 to a minute
4:03 – Motorized Pedicure Massage Chair
– Broadway Spa on Broadway b/w 11th St. and 12th St.
- To relax the user by moving prods around the back, and time the
heating of the water and foot massage functionality
- About 45 minutes
4:09 – Noise-cancelling Headphones
- Broadway b/w 12th St. and 13th St.
- To cancel out ambient noise so user can hear their music more clearly
- Ongoing
4:11 – Music Previewer Device
– Virgin in Union Square
- To allow the user to listen to music from a large selection of CD's
without working at it
- Up to five or ten minutes
4:12 – DJ Sound System
- Same Location
- To allow the DJ to easily select music and broadcast it to the store
- Ongoing
4:15 – Digital Cash Register
- Same Location
- To keep track of inventory as it is bought by shoppers, and register
money as it comes into the store
- 1 to 2 minutes per transaction
4:15 – Touch Screen
- Same Location
- To translate finger movements into screen and computer actions
- 1 to 2 seconds
4:17 – CD Player
- Same Location
- To translate digital media into sound form, as requested by the user
- Ongoing
4:22 – Digital Person Counter
- Same Location
- To monitor the number of people entering and leaving a store
- Instantaneous
4:24 – Police Dispatch Device
– Broadway and 14th St.
- To communicate with headquarters and other police officers, and
receive instructions.
- up to 1 minute
4:25 – Bluetooth Ear Device
- Broadway and 14th St.
- To relay sound into electricity and wire it to a digital phone, and
receive signals from a phone and translate them into sound
- Ongoing
4:27 – MetroCard Fare Checker
– Union Square Subway
- To read a fare card, match it to a virtual account, and display how
much money is in it
- 1-2 seconds
4:27 – MetroCard Swiper
- Union Square Subway
Subway Card Swiper
- To read a Subway card, access a virtual account, debit one ride from
the amount in it, and unlock the turnstyle.
- 2-3 seconds
4:27 – MetroCard Buyer
- Union Square Subway
- Allows users to buy a subway card and add money to an associated
virtual account
- About 30 seconds
4:30 – Checkout Crowd Control System Monitor– Whole Foods Market in Union Square
4:30 – Checkout Crowd Control System Flipper Switch – Same Location
4:30 – Checkout Crowd Control System PA System - Same Location
4:30 – Checkout Crowd Control System Flipper Switch Light - Same Location
- To control how long shoppers stand in line by signaling when each
next cashier is available, and keeping the lines even by randomizing
which line the next shopper comes from. It also ensures that no one
cashier becomes overwhelmed.
- 0 to 3 minutes
4:34 – Automatic Doors
- Same Location
Automatic Doors
- To open doors automatically via a motion sensor so shoppers can enter
or leave a building without using their hands.
- 1 second
Time Seen,
Purpose,
Average time for an interaction.
3:34 – Crosswalk Sign
– Waverly Place and Broadway
- To time and signal to pedestrians when it is safe for them to cross the street
- 0 to 60 seconds
3:38 – Bus MetroCard machine
- Waverly Place and Broadway
- To check and debit credits from a rider's account and signal to the
driver that they're qualified to ride
- About 5 seconds
3:39 – Electric Wheelchair
– Waverly Place and Broadway
- To provide personal locomotion without the use of legs
- Ongoing
3:41 – PS3 + X360 System and Controller
– GameStop on Broadway b/w Waverly Place and 8th Street
- To simulate the visual feedback of a football game depending on input
from a game controller
- 4 to 5 hours?
3:41 – Credit Card Swiper
– Same Location
- To identify and then access and debit money from a bank account, or
to access and place a charge against a credit card
- 10 to 15 seconds
3:42 – Security Monitor
– Same Location
- To monitor and let shoppers know that they can be seen
- Instant
3:43 – UPC Scanner
- Same Location
- To keep track of outgoing products from the store's stock as they're
sold to customers
- 1 to2 seconds
3:45 – Digital Watch
– 8th Street and Broadway
-To measure time
-1 to 2 seconds
3:47 – Security Scanner
– Broadway b/w 8th St. and 9th St.
- To notify staff when a piece of inventory leaves the store without
first going through the checkout process
- Instantaneous
3:51 – Digital Camera
- Broadway b/w 8th St. and 9th St.
-To record light waves in digital media
-5 to 10 seconds
3:51 – ATM
– HSBC Broadway b/w 8th St. and 9th St.
- To debit a user's bank account and dispense cash by that amount
-30 seconds to 1 minute
3:53 – Digital Bus Sign
- Broadway and 9th St.
-To inform riders which route a bus is currently driving
-1-2 seconds
3:55 – Personal Computer (screen, keyboard)
– Chase Bank on Broadway and 10th St.
- To take in banking information from the banker and display necessary
client details
- Ongoing
3:56 – Traffic Light
- Broadway and 10th St.
- To control the flow of cars and other vehicle traffic, to signal when
it's safe to accelerate and when it's necessary to stop
- 0 to a minute
4:03 – Motorized Pedicure Massage Chair
– Broadway Spa on Broadway b/w 11th St. and 12th St.
- To relax the user by moving prods around the back, and time the
heating of the water and foot massage functionality
- About 45 minutes
4:09 – Noise-cancelling Headphones
- Broadway b/w 12th St. and 13th St.
- To cancel out ambient noise so user can hear their music more clearly
- Ongoing
4:11 – Music Previewer Device
– Virgin in Union Square
- To allow the user to listen to music from a large selection of CD's
without working at it
- Up to five or ten minutes
4:12 – DJ Sound System
- Same Location
- To allow the DJ to easily select music and broadcast it to the store
- Ongoing
4:15 – Digital Cash Register
- Same Location
- To keep track of inventory as it is bought by shoppers, and register
money as it comes into the store
- 1 to 2 minutes per transaction
4:15 – Touch Screen
- Same Location
- To translate finger movements into screen and computer actions
- 1 to 2 seconds
4:17 – CD Player
- Same Location
- To translate digital media into sound form, as requested by the user
- Ongoing
4:22 – Digital Person Counter
- Same Location
- To monitor the number of people entering and leaving a store
- Instantaneous
4:24 – Police Dispatch Device
– Broadway and 14th St.
- To communicate with headquarters and other police officers, and
receive instructions.
- up to 1 minute
4:25 – Bluetooth Ear Device
- Broadway and 14th St.
- To relay sound into electricity and wire it to a digital phone, and
receive signals from a phone and translate them into sound
- Ongoing
4:27 – MetroCard Fare Checker
– Union Square Subway
- To read a fare card, match it to a virtual account, and display how
much money is in it
- 1-2 seconds
4:27 – MetroCard Swiper
- Union Square Subway
Subway Card Swiper
- To read a Subway card, access a virtual account, debit one ride from
the amount in it, and unlock the turnstyle.
- 2-3 seconds
4:27 – MetroCard Buyer
- Union Square Subway
- Allows users to buy a subway card and add money to an associated
virtual account
- About 30 seconds
4:30 – Checkout Crowd Control System Monitor– Whole Foods Market in Union Square
4:30 – Checkout Crowd Control System Flipper Switch – Same Location
4:30 – Checkout Crowd Control System PA System - Same Location
4:30 – Checkout Crowd Control System Flipper Switch Light - Same Location
- To control how long shoppers stand in line by signaling when each
next cashier is available, and keeping the lines even by randomizing
which line the next shopper comes from. It also ensures that no one
cashier becomes overwhelmed.
- 0 to 3 minutes
4:34 – Automatic Doors
- Same Location
Automatic Doors
- To open doors automatically via a motion sensor so shoppers can enter
or leave a building without using their hands.
- 1 second
One Sensor, Sensing
This here is a light sensor, compliments of radio shack, giving me some feedback. Way to go, little sensor!
And here's the code:
Here's the Arduino all wired up and ready to go | And here is a readout showing it's receiving |
With light | Without light! |
And here's the code:
int analogReading; //variable int size because adc number potentially as big as 1024
int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int led = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
void setup()
{
beginSerial(9600); //set up communication back to pc
//don't forget to press "serial monitor button"
}
void loop()
{
analogReading = analogRead(0); //can only use pins 0-5
Serial.println(analogReading); //talk back to pc
potValue = analogRead(potPin); // read the pot value
analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
Serial.println(potValue); // print the pot value back to the debugger pane
delay(10); // wait 10 milliseconds before the next loop
}
Sunday, September 14, 2008
Orality and Litteracy
I remember reading in an article that when humans converted from typewriters to computers in the early eighties there was a bit of a paradigm shift in writing. And not in terms of sheer volume or ease of use, such as Clay Shirky argues occurred with the printing press.
This change was caused by the new ability to revise with no consequences, with no need for the old amount of forethought. Instead of needing to have sentences, chapters and plot worked out in the writer's head, all that was needed was the whim to write at that moment. The article phrased it this way: instead of writing because the writer had something to say, now they could write to find out if they had something to say.
I think that this is the message that the 1981 book Orality and Literacy, by Walter J. Ong, is trying to get at. For a book on modes of communication, he makes it a bit difficult - the tone is academic and condescending in a way that would probably be edited out in the first draft today, even in a thesis. But style issues aside, he seems to agree. Big shifts in communication mean complicated shifts in how users relate to themselves and their surroundings. For example, the idea of utilitarian versus abstract category assignment, or the concept of of formulaic epic writing versus our current horror of cliches, both point to a modification of the thinking process itself.
It seems a little simplistic to state that sound is community-building, while participating in literacy is much more of an individual activity. Illiteracy in oral societies is caused by the same influences that also favor community: An early stage of technological development, a need for food-sharing structures, etc. Development gives rise to literacy and individualism at the same time, as the survival of a group becomes less and less determined on the full participation of every member. The relationship is a correlation, not a causation.
In an indirect sense, written literature certainly increases communal participation by giving individuals access to shared experiences and opinions. As Ethan Zuckerman pointed out during last week's Applications lecture, access to enough non-verbal litterature produces a very tight-knit community indeed.
However, I find that the concept of a history that can be changed according to current politics to be a particularly interesting side effect of an oral culture. I've often thought I'd have hated to be born 10 years after my 1980 birthdate because it would be terrible to have all my childhood faux pas committed to the ether forever. As is, I have college postings on fan sites and an interview from a newspaper that will forever appear linked to my name for all eternity. It's easy to understand an oral culture's dismay at the idea of an immutable history.
Lots of unsuccessful high school poets wonder why the romantic poem in their English text is high art, but the similar version in their blog about the girl in the seat next to them isn't. Ong, no matter how long-winded, would say that without the historical conditions to create the thought process that gives rise to a piece, the student is only copying the marks on the paper. There simply is no way to recapture an earlier mindset once a culture has been rewired by new communication techniques.
This change was caused by the new ability to revise with no consequences, with no need for the old amount of forethought. Instead of needing to have sentences, chapters and plot worked out in the writer's head, all that was needed was the whim to write at that moment. The article phrased it this way: instead of writing because the writer had something to say, now they could write to find out if they had something to say.
I think that this is the message that the 1981 book Orality and Literacy, by Walter J. Ong, is trying to get at. For a book on modes of communication, he makes it a bit difficult - the tone is academic and condescending in a way that would probably be edited out in the first draft today, even in a thesis. But style issues aside, he seems to agree. Big shifts in communication mean complicated shifts in how users relate to themselves and their surroundings. For example, the idea of utilitarian versus abstract category assignment, or the concept of of formulaic epic writing versus our current horror of cliches, both point to a modification of the thinking process itself.
It seems a little simplistic to state that sound is community-building, while participating in literacy is much more of an individual activity. Illiteracy in oral societies is caused by the same influences that also favor community: An early stage of technological development, a need for food-sharing structures, etc. Development gives rise to literacy and individualism at the same time, as the survival of a group becomes less and less determined on the full participation of every member. The relationship is a correlation, not a causation.
In an indirect sense, written literature certainly increases communal participation by giving individuals access to shared experiences and opinions. As Ethan Zuckerman pointed out during last week's Applications lecture, access to enough non-verbal litterature produces a very tight-knit community indeed.
However, I find that the concept of a history that can be changed according to current politics to be a particularly interesting side effect of an oral culture. I've often thought I'd have hated to be born 10 years after my 1980 birthdate because it would be terrible to have all my childhood faux pas committed to the ether forever. As is, I have college postings on fan sites and an interview from a newspaper that will forever appear linked to my name for all eternity. It's easy to understand an oral culture's dismay at the idea of an immutable history.
Lots of unsuccessful high school poets wonder why the romantic poem in their English text is high art, but the similar version in their blog about the girl in the seat next to them isn't. Ong, no matter how long-winded, would say that without the historical conditions to create the thought process that gives rise to a piece, the student is only copying the marks on the paper. There simply is no way to recapture an earlier mindset once a culture has been rewired by new communication techniques.
Saturday, September 13, 2008
The Waterfalls in the rain
There's an odd little science fiction book of Eric Flint's called 1633 whose concept, as far as I understand it, is of a modern Army town from West Virginia magically transported to 17th century France. The whole thing is bizarrely conservative, with characters breaking off at odd moments in the plot to advocate guns and prayer in schools, and I really remember nothing about it except one scene.
When the inevitable military clash comes, the 17th Century opposition isn't impressed with planes. The sight of chunks of metal cruising through the sky is so far removed from their realm of experience that they're not sure how to react except to shrug and continue their work. Speedboats, however, speedboats floor them. They've seen boats before, and these are just like the devices they know, but fast and small and able to make impressive noise. The speedboats are what they freak out over.
This is the scene I had playing over and over in my head when I went to visit the Waterfalls today. It wasn't great timing; coming through the bleak drizzle of Wall Street, pushing through all that concrete to find...a grey river and even greyer sky. At the end of Pier 11 you can see all four Waterfalls at once, just me and a tiny Asian man fishing giant wriggling eels out of the spray.
Well, they're big, the waterfalls. They're certainly huge. But like the 17th Century French, I really wasn't quite sure what I was supposed to be looking at. There was no context or comparison. Yes they were big, yes there was a lot of water, but what of it? Why go through all that effort to mildly aerate a bit of liquid? It was coming down quite a bit as it was, no? Pick up some water, drop some water...perhaps they were meant as some kind of zen meditation exercise?
The only exception for me was the falls under the Brooklyn Bridge. The falls are set up so that it looks as though water were coming from the bridge itself, flowing back into the river. Now this - water coming from somewhere and flowing somewhere else, this is something I have a frame of reference for. It was is if Manhattan had sprung a leak. I remember reading in Alan Weisman's A World Without Us that without electricity, Manhattan's subway tunnels would be flooded in three days. Seeing the water seemingly gushing from the Brooklyn Bridge, I can picture it. The manholes exploding into fountains, the avenues slowly sinking into canal-dom...
So I suppose my reaction to the chilly hour spent in the drizzle at the end of Pier 11 is this. When we see a beautiful woman walking down a street, we might admire her beautiful hair and sexy dress. But to be sure, just watching a disembodied set of tresses and miniskirt float down Broadway would be confusing indeed, no matter how well styled and fashionable. That's because what we're really admiring is the hair or dresses ability to accent the woman herself, to draw attention to her hips or pretty face.
No one really visits a waterfall for the water. The water is an accent to show off how high a cliff truly is, it's an accent to contrast the darkness of the rock or the lushness of the surrounding vegetation. Visitors at Niagara falls look up, around, or at most, at the rocks below to watch the splash. No one spends their honeymoon cruise staring at the flow of liquid as it goes by.
I truly think that if all they had available to their visual line of sight was that moving sheet of water, they'd be as bewildered as those 17th Century Frenchmen trying to understand the point of airplanes.
When the inevitable military clash comes, the 17th Century opposition isn't impressed with planes. The sight of chunks of metal cruising through the sky is so far removed from their realm of experience that they're not sure how to react except to shrug and continue their work. Speedboats, however, speedboats floor them. They've seen boats before, and these are just like the devices they know, but fast and small and able to make impressive noise. The speedboats are what they freak out over.
This is the scene I had playing over and over in my head when I went to visit the Waterfalls today. It wasn't great timing; coming through the bleak drizzle of Wall Street, pushing through all that concrete to find...a grey river and even greyer sky. At the end of Pier 11 you can see all four Waterfalls at once, just me and a tiny Asian man fishing giant wriggling eels out of the spray.
Well, they're big, the waterfalls. They're certainly huge. But like the 17th Century French, I really wasn't quite sure what I was supposed to be looking at. There was no context or comparison. Yes they were big, yes there was a lot of water, but what of it? Why go through all that effort to mildly aerate a bit of liquid? It was coming down quite a bit as it was, no? Pick up some water, drop some water...perhaps they were meant as some kind of zen meditation exercise?
The only exception for me was the falls under the Brooklyn Bridge. The falls are set up so that it looks as though water were coming from the bridge itself, flowing back into the river. Now this - water coming from somewhere and flowing somewhere else, this is something I have a frame of reference for. It was is if Manhattan had sprung a leak. I remember reading in Alan Weisman's A World Without Us that without electricity, Manhattan's subway tunnels would be flooded in three days. Seeing the water seemingly gushing from the Brooklyn Bridge, I can picture it. The manholes exploding into fountains, the avenues slowly sinking into canal-dom...
So I suppose my reaction to the chilly hour spent in the drizzle at the end of Pier 11 is this. When we see a beautiful woman walking down a street, we might admire her beautiful hair and sexy dress. But to be sure, just watching a disembodied set of tresses and miniskirt float down Broadway would be confusing indeed, no matter how well styled and fashionable. That's because what we're really admiring is the hair or dresses ability to accent the woman herself, to draw attention to her hips or pretty face.
No one really visits a waterfall for the water. The water is an accent to show off how high a cliff truly is, it's an accent to contrast the darkness of the rock or the lushness of the surrounding vegetation. Visitors at Niagara falls look up, around, or at most, at the rocks below to watch the splash. No one spends their honeymoon cruise staring at the flow of liquid as it goes by.
I truly think that if all they had available to their visual line of sight was that moving sheet of water, they'd be as bewildered as those 17th Century Frenchmen trying to understand the point of airplanes.
Tuesday, September 9, 2008
A piano combination lock
This will probably be the only week with three Phys Comp entries. Following the basic wiring exercise and the earring switch, I present you with a Keyboard Combination Lock! The idea here is to mock up a "lock" where the user must enter a particular "melody" or order of keys to make an LED light up. Along the way, they should get clues that they are on the right track, or failing miserably. This is done with a series of switches, one for each piano key.
To start with, I found a glove on the Junk shelf, pre-wired with some conductive material on the fingertips, soldered to wires. I cut a finger off and soldered its wire to my incoming power (indirectly wired to 5V on the Arduino Chip). Then I set up seven possible switches, each complete with its own digital input (D1-D7 on the Arduino) and a resistor running to ground for when each individual switch was not in use.
The inputs for the switches were stretched across a printout of a piano keyboard on top of some wood for stability. This gives the user to ability to complete each of the seven switches at will. D8 and D9 were wired to a red and green LED (through protective resistors) to give the user feedback on how they were doing.
The "correct" sequence I chose was pretty arbitrary - an F key followed by a G key. that is, an input into D1 followed by D2. Pressing any other key, including pressing the two correct inputs out of order, causes a red "error" LED to light up briefly. If they get both correct, the green flashing LED of happiness turns on. The green light also blips when the first key is pressed successfully so the user knows they're on the right track. However, if the second key is still incorrect, they'll have to start all over again.
Just to be careful, I included a fail-safe to make sure that only one key was being pressed at a time to keep the user from cheating by just pressing down a piece of metal on all the keys at once. There's a small pause after the first key is pressed correctly to give the user time to lift thier finger.
The program is pretty simple. The Arduino watches all the keys waiting for inputs. There are three main possibilities: The first key is pressed (at the right or the wrong time), the second key is pressed (also at the right or the wrong time), and any other key is pressed (always at the wrong time, 'cause they're not part of the sequence). Nested if statements check to make sure those inputs are being triggered in the right sequence, and force the user to start over if they're not. D8 and D9 are designated outputs - they flash a red, green, or a green pulsing pattern to give the user feedback on what's going on.
Here's the code!
The finger from a glove with conductive mesh on the tip, soldered to a wire | The Arduino, all wired up. D1-D7 are inputs, D8 and 9 are outputs |
To start with, I found a glove on the Junk shelf, pre-wired with some conductive material on the fingertips, soldered to wires. I cut a finger off and soldered its wire to my incoming power (indirectly wired to 5V on the Arduino Chip). Then I set up seven possible switches, each complete with its own digital input (D1-D7 on the Arduino) and a resistor running to ground for when each individual switch was not in use.
The breadboard, wired up. The red wires on the left go to the Ardrino, the ones on the right go to the keybord | The keyboard - a printout on wood, wires are taped down at the top and bottom |
The inputs for the switches were stretched across a printout of a piano keyboard on top of some wood for stability. This gives the user to ability to complete each of the seven switches at will. D8 and D9 were wired to a red and green LED (through protective resistors) to give the user feedback on how they were doing.
The first key (F) being pressed in the correct sequence. | F being pressed out of order. User must start over |
The "correct" sequence I chose was pretty arbitrary - an F key followed by a G key. that is, an input into D1 followed by D2. Pressing any other key, including pressing the two correct inputs out of order, causes a red "error" LED to light up briefly. If they get both correct, the green flashing LED of happiness turns on. The green light also blips when the first key is pressed successfully so the user knows they're on the right track. However, if the second key is still incorrect, they'll have to start all over again.
Another key being pressed at any time. User must start over. | The sequence was entered correctly. It's flashing, take my word for it. |
Just to be careful, I included a fail-safe to make sure that only one key was being pressed at a time to keep the user from cheating by just pressing down a piece of metal on all the keys at once. There's a small pause after the first key is pressed correctly to give the user time to lift thier finger.
The program is pretty simple. The Arduino watches all the keys waiting for inputs. There are three main possibilities: The first key is pressed (at the right or the wrong time), the second key is pressed (also at the right or the wrong time), and any other key is pressed (always at the wrong time, 'cause they're not part of the sequence). Nested if statements check to make sure those inputs are being triggered in the right sequence, and force the user to start over if they're not. D8 and D9 are designated outputs - they flash a red, green, or a green pulsing pattern to give the user feedback on what's going on.
Here's the code!
/*Piano combination lock. This code'll strobe a green led until the board is reset if the first switch (in this case and F key) followed by a G key, is pressed in that order. It will also give a little encouraging green blip if the first key is pressed correctly. If any other key is pressed for the first selection (including the G key), a red light will blip, and you'll have to start over. Likewise for the second key. That's it! */
// declare variables:
int switchPin1 = 1; // digital input pin for switch 1
int switchPin2 = 2;
int switchPin3 = 3;
int switchPin4 = 4;
int switchPin5 = 5;
int switchPin6 = 6;
int switchPin7 = 7;
int greenLEDpin = 8; // digital output pin for an LED
int redLEDpin = 9; // digital output pin for an LED
int switchState1 = 0; // the state of the switch1
int switchState2 = 0;
int switchState3 = 0;
int switchState4 = 0;
int switchState5 = 0;
int switchState6 = 0;
int switchState7 = 0;
int conditionsFilled = 0; //Keeps track of how many conditions so far have been filled
int timer = 0; // Lets us loop if the user is successful
void setup() {
pinMode(switchPin1, INPUT); // set the switch pin to be an input
pinMode(switchPin2, INPUT); // set the switch pin to be an input
pinMode(switchPin3, INPUT); // set the switch pin to be an input
pinMode(switchPin4, INPUT); // set the switch pin to be an input
pinMode(switchPin5, INPUT); // set the switch pin to be an input
pinMode(switchPin6, INPUT); // set the switch pin to be an input
pinMode(switchPin7, INPUT); // set the switch pin to be an input
pinMode(greenLEDpin, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLEDpin, OUTPUT); // set the red LED pin to be an output
}
void loop() {
// read the switch inputs:
switchState1=digitalRead(switchPin1); //Sets the inputs to variables that won't take so long to type
switchState2=digitalRead(switchPin2);
switchState3=digitalRead(switchPin3);
switchState4=digitalRead(switchPin4);
switchState5=digitalRead(switchPin5);
switchState6=digitalRead(switchPin6);
switchState7=digitalRead(switchPin7);
if ((switchState3 + switchState4 + switchState5 + switchState6 + switchState7) != 0) {
//if (switchState3 == 1) {
conditionsFilled = 0; //No matter if it's for the first or second slot, any of these is always wrong. Go back to the beginning
digitalWrite (redLEDpin, 1); //just so they feel really bad about it
delay (500);
digitalWrite (redLEDpin, 0);
}
if (switchState1 == 1) {
// if the correct first switch is closed:
if (conditionsFilled != 0) { //makes sure this is not something they're doing for the second key
// They failed to guess the second or third option, so the entire thing gets reset
//we do not set conditions filled equal to zero, because this could be the start of a new combo too, even if they've pressed it before
digitalWrite (redLEDpin, 1); //just so they feel really bad about it
delay (500);
digitalWrite (redLEDpin, 0);
delay (1000); //a delay so the program doesn't see your ongoing finger pressing the input as an incorrect second input
conditionsFilled = 0;
}
else if (((switchState2 + switchState3 + switchState4 + switchState5 + switchState6 + switchState7) < 1) && (conditionsFilled == 0))
{
//and if this is the first number selected, and if they're not just mashing down all they keys at once
digitalWrite (greenLEDpin, 1);
delay (500);
digitalWrite (greenLEDpin, 0);
conditionsFilled = 1; //let the code know the first condition has been filled
}
}
if (switchState2 == 1) { //if they've selected the second one
//and they're not just mashing down all the keys, and it's the second selection
if (((switchState1 + switchState3 + switchState4 + switchState5 + switchState6 + switchState7 ) < 1) && (conditionsFilled == 1)) {
while(timer < 5000){
digitalWrite(greenLEDpin, 1); // sets the LED on
delay(100); // waits for a second
digitalWrite(greenLEDpin, 0); // sets the LED off
delay(100); // do something repetitive 200 times
timer++;
}
}
else if (conditionsFilled == 0){
digitalWrite (redLEDpin, 1); //just so they feel really bad about it
delay (500);
digitalWrite (redLEDpin, 0);
}
}
}
Subscribe to:
Posts (Atom)