Beverage cabinet update!
Our interactive beverage cabinet is coming along... slowly! Alex and I have been working on the Arduino code for the past ten days or so, but we've hit a number of obstacles along the way and are still working through the kinks.
The cabinet has five switches, one in each compartment. When a bottle is removed, a switch is flipped in that compartment, triggering a music track and light sequence corresponding to that bottle.
Initially, we figured that the code would be relatively straightforward - it's just five switches, a few lights and some tunes, right? Well, yes, but using multiple switches to control multiple light sequences through the MIDI dimmer was a little trickier than anticipated.
Our first step was getting the MIDI dimmer to communicate with the Arduino. We tested this using Rory Nugent's test code.
Next, we programmed the dimmer to begin the light sequence when a switch is turned on, and stop the sequence then the switch is turned off, without delays (which cause problems as the Arduino stops).
When we tested the code using the lightGo() and lightHalt() functions, the light turned on as hoped when the switch is pressed, but didn't begin the incremental dimming up & down.
So, we sought advice and learned that the parts of code involving (switchState ! == lastSwitchState) and if (millis() - previousMillis > interval) were the source of our issues. So, we added arrays for brightness values, switchState, lastSwitchState, previousMillis and interval variables for each switch, ending up with the following code:
MIDI Dimmer code
int midiPin = 1; // digital output pin for the midi dimmer
int lastSwitchState[5]; // previous state of the switch
int lightToggle[5]; //DOES THIS NEED TO BE AN ARRAY? Variable for toggling the light at max and min values
int switchState[5]; // current state of each switch
int lastswitchState[5]; // previous state of each switch
int previousMillis[5]; //DOES THIS NEED TO BE LONG?
int brightness[5]; // array of brightnesses for each light
int switchPins[] = {
2,3,4,5,6}; // digital input array to hold the switch pin numbers
// brightness goes from 1-127...not sure what goes in the curly brackets below
//int brightness[] = { ? }
void setup() {
for (int thisChannel = 0; thisChannel < 5; thisChannel++) {
//initialize switch pins as inputs
pinMode(switchPins[thisChannel], INPUT);
pinMode(midiPin, OUTPUT); //initialize midi dimmer as output
Serial.begin(31250); // set MIDI baud rate
}
}
void loop() {
for (int thisChannel = 0; thisChannel < 5; thisChannel++){
// read the switch:
switchState[thisChannel] = digitalRead(switchPins[thisChannel]);
//if the switch has changed,
// compare the switchState to its previous state
if (switchState[thisChannel] != lastswitchState[thisChannel]) {
// if the switch has changed from off to on:
if (switchState[thisChannel] == HIGH) {
// if the current state is HIGH then the switch
// went from off to on:
lightGo(thisChannel, 10); //REPLACE 10 with "interval"
}
else { // else the switch changed, going from on to off:
lightGo(thisChannel, 3); //REPLACE 10 with "interval"
}
// save the current state as the last state,
//for next time through the loop
lastswitchState[thisChannel] = switchState[thisChannel];
}
else { // else the switch didn't change.
// dim all the light channels:
brightness[thisChannel]--;
lightGo(brightness[thisChannel], 30);
}
}
//if the switch is off:
if (switchState == LOW) {
//call the lightHalt function
lightHalt (0);
//lightHalt (1);
//lightHalt (2);
}
*/
}
// data1 should be from 0-5, and tells the dimmer which light group
// data2 should be from 0-127 and represents the brightness
void noteOn(char cmd, char data1, char data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}
void lightGo (int thisChannel, long interval) { //
if ((millis() - previousMillis[thisChannel]) > interval) {
//if the light is on at all
if (brightness[thisChannel] == 127) {
lightToggle[thisChannel] = 0;
// Serial.println("here");
}
//if light is off
else if (brightness[thisChannel] == 0) {
lightToggle[thisChannel] = 1;
}
if (lightToggle[thisChannel]==1) {
brightness[thisChannel]++;
}
else {
brightness[thisChannel]--;
}
//turn on the light
noteOn(0x90, thisChannel, brightness[thisChannel]);
// save the last time you blinked the light
previousMillis[thisChannel] = millis();
}
}
void lightHalt(int thisChannel) {
//if the switch is off, turn off the light:
noteOn(0x90, thisChannel, 0);
//save the last time the light blinked:
previousMillis[thisChannel] = millis();
}
We're still working on figuring out and finishing this code and making it work. In the meantime, we've hard-coded everything in the hope of making it work.
MP3 Trigger
The MP3 Trigger allowed two ways for us to play MP3 files through Arduino: we could either use the 7 trigger pins on the board to directly trigger 7 pre-selected tracks, or use serial communication through Arduino to enable remote triggering of all tracks on the board, with the added advantage of volume control. We opted for the latter - however, the MIDI dimmer was already using the serial port, so we got the MP3 Trigger functioning through software serial.
We loaded our tracks onto the MP3 Trigger, and used the XX library to link the songs to specific switches.
Switches = Wicked Witches!
We tried out one switch to see if the music and lights would work together and after a bit of troubleshooting, it worked! However, when we tried the cabinet with more than one switch, everything went a bit crazy.
And that's where we are right now. We've worked our posteriors off, we've learned a TON, and we're pretty certain that we're almost there.
Images/video of our progress shall be forthcoming. But first, sleep. And breakfast.
Pcomp final: Interactive Liquor Cabinet
Over the past few weeks, Alex Vessels and I have brainstormed on the floor at ITP, in the East Village, Chinatown and everywhere in between to settle upon the perfect form factor for our party device. Somewhere along the way, we settled upon the perfect form factor for our party device: an interactive liquor cabinet that will create a different type of party mood, depending on which liquor is selected.
We're using an existing antique cabinet with five compartments, which will light up when the cabinet is opened. There will be one object placed in each compartment. When an item is removed from the cabinet, a song corresponding to that object will play, and a light sequence will kick in. For example, take out the bottle of Jameson, and you'll hear the Pogues and be dazzled by a green light display. Or select the Jim Beam, and you'll hear Guns 'n' Roses and be dazzled by red and blue flashing lights.
We're experimenting with building various types of switches to place on the shelves of the cabinet, and we're currently learning to use the MIDI dimmer from the ER to control AC lights. For now, we'll use the Processing Minim library and a laptop to control the music - eventually, we'll probably switch to aWave Shield, which can be hidden inside the cabinet (and eliminating the laptop from the equation).
Below is a photo of the cabinet as is. We're hoping to keep the exterior appearance intact and preserve the old-time aesthetic.
Stupid Pet Trick: Attention-grabbing handbag
Every handbag makes a statement. I'm pretty sure that this shiny yellow one states something to the effect of, "Look at me! Look at me! Look at me!"
There are a lot of handbags out there, though - many of them larger, shinier and arguably more attractive than my awesomely bright and cheerful accessory. For our Stupid Pet Trick assignment, I decided to make some alterations to ensure that my yellow bag continues to stand out in any crowd. An LED on the bag ensures that it's noticed at all times - but upon sight of any handbag that poses a threat, a squeeze of a black coin purse that discreetly houses an FSR sensor causes two other LEDs in the bag to turn on, depending on the amount of pressure exerted upon the coin purse.
The portability of the handbag was severely decreased due to wires, a breadboard and Arduino - which also filled the bag to capacity! - so next time, a breadboard-less, soldered circuit will be the way to go.
Stupid Pet Trick: Attention-grabbing handbag from katherine keane on Vimeo.
Reviewing the Stupid Pet Tricks in class, we discussed possible ways to push this project further. Suggestions included:
- Use the magnetic snap on the bag as a switch to activate a security alarm, so the bag would light up when opened, OR add an audible alarm using the Tone library
- Put the sensor on the bag's shoulder strap, to require less input from the wearer to make the lights turn on. On the other hand, the in-hand FSR sensor provides the wearer with a greater degree of control to decide when more lights are necessary to keep the bag in the spotlight.
- For a subtler effect, create a bag that "glows" upon the wearer's command: construct the bag's exterior from a less opaque material, and the lining from a material that diffuses light, and place LEDs between the exterior and lining.
- Place the LEDs inside the bag, and use the magnetic snap as a switch to turn them on when the bag is opened, enabling the wearer to easily find specific contents within.
Below is the code I used:
int sensorPin = 0; // select the input pin for the FSR int ledPinOne = 9; //select the digital output pin for the 1st LED int ledPinTwo = 6; //select the digital output pin for the 2nd LED int ledPinThree = 5; //select the pin for the 3rd LED int sensorValue = 0; // the analog reading from the FSR resistor divider
void setup() {
Serial.begin(9600); pinMode(sensorPin,INPUT); //set the sensor as the input pinMode(ledPinOne,OUTPUT); //set 1st LED as output pinMode(ledPinTwo,OUTPUT); //set 2nd LED as output pinMode(ledPinThree,OUTPUT); //set 3rd LED as output }
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
//sensorValue = sensorValue/4;
Serial.println(sensorValue/4); // print the sensor value in the debugger
if (sensorValue <=100) {
// turn on ledPinOne
analogWrite(ledPinOne, 127);
analogWrite(ledPinTwo, 0);
analogWrite(ledPinThree, 0);
}
else {
//if the sensor value is between 120 and 180
if ((sensorValue > 120)&&(sensorValue <=180)){
analogWrite(ledPinOne, 255);
analogWrite(ledPinTwo, 127);
analogWrite(ledPinThree, 0);
}
else {
//if the sensor value is between 181 and 255
if ((sensorValue > 181)&&(sensorValue <=255)){
analogWrite(ledPinOne, 255);
analogWrite(ledPinTwo, 255);
analogWrite(ledPinThree, 127);
} } } }
