So I got the code and circuitry to all work correctly for my "Let's Get It On" Lamp. I am so excited to get it working on the reals.
Yet, i'm still havin some issues with the pants circuitry. Sometimes the fly signal works, others it doesn't.
*Side note: there pants have enough batteries in them to melt through the crotch. This concerns me a bit and it could probably be wired in a more optimal way, with less batteries, but I need a break from this. FYI: Not for actual wearing!
Here's some vid and pics of my progress. :)
lamp_circuit from Lynn WasHere on Vimeo.
/////-------------------------------------------------CODE-----------------------------------------------------/////
/*
* BlinkColorFader -- Example of how to select color & brightness
* with two pots
*
* For more info on how to use pots and analog inputs see:
* http://www.arduino.cc/en/Tutorial/AnalogInput
*
* BlinkM connections to Arduino
* PWR - -- gnd -- black -- Gnd
* PWR + -- +5V -- red -- 5V
* I2C d -- SDA -- green -- Analog In 4
* I2C c -- SCK -- blue -- Analog In 5
*
* Note: This sketch sends to the I2C "broadcast" address of 0,
* so all BlinkMs on the I2C bus will respond.
*/
#include "Wire.h"
#include "BlinkM_funcs.h"
//address for BlinkM
#define blinkm_addr 0x00
// INPUT: Potentiometer should be connected to 5V and GND
int potPin = 0; // Potentiometer output connected to analog pin 0
#define potPin 0 // analog in pins from zipper signal to control LED fade color: white to red
#define ARRAY_SIZE 5 //this is the array size
int potNums[ARRAY_SIZE]; //this reads AND stores 10 numbers from the potentiometer input.
int pot_val; //potentiometer value from zipper position on jeans
// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// LED's cathodes should be connected to digital GND
int pPin = 7; //PLAY, conncected to pin8
// Program variables
int currentPlace = 0; //this is the total value
int placeHolder = 0; //placehoder for each spot in the array
int ave = 0; //average pot input numbers (normalize/smooth the input signal)
//SETUP
void setup()
{
BlinkM_beginWithPower();
BlinkM_stopScript(blinkm_addr); // turn off startup script
Serial.begin(9600); // ...set up the serial ouput in 0004 format
for (int i = 0; ARRAY_SIZE < 5; i++)
{
potNums[i] = 0; //fills all values in the array to 0
}
pinMode(pPin, OUTPUT);
}
// MAIN
void loop()
{
currentPlace -= potNums[placeHolder]; //subtract the last reading from array
potNums[placeHolder] = analogRead(potPin); // read the potentiometer value at the input pin
currentPlace += potNums[placeHolder]; //add to the array
placeHolder++; //add 1 to the placeHolder each loop
if(placeHolder >= ARRAY_SIZE)
{
placeHolder = 0; //if the placeHolder goes thru the whole array,
} //then loop back to the 1st spot in the array
ave = currentPlace/ARRAY_SIZE; //calc the average
//Serial.println(ave); // send it to the computer (as ASCII digits)
pot_val = analogRead(potPin); // read the hue pot
//Serial.println(pot_val);
//-------------------------------------------LED LIGHT------------------------------------------
//light should fade from white when zipper is up to red when zipper is down
BlinkM_fadeToRGB( blinkm_addr, 255, int(pot_val/3.5), int(pot_val/3.5)); // adjust the green and blue to decrease with pot values
//-------------------------------------------MUSIC------------------------------------------
if (ave > 600) // Upper third of potentiometer"s range (600)
{
digitalWrite(pPin, HIGH); //keep digital pin open if zipper is near top
}
else if (ave >= 200 && ave <= 500) // Middle third of potentiometer's range (100 - 150)
{
digitalWrite(pPin, HIGH); //keep digital pin open if zipper is in middle
}
else if (ave < 100) // Lowest third of the potentiometer's range (50 - 100)/turn on music here (< 100)
{
digitalWrite(pPin, LOW); //put digital pin to GROUND if zipper is at bottom
}
//----------------DEBUG-----------------------------------------------------
Serial.print("potVal(ave):");
Serial.println(ave);
delay(50); // wait a bit because we don't need to go fast
}
Comments
You can follow this conversation by subscribing to the comment feed for this post.