/* *Velas *Caroline Brown *ITP NYU *Fall 2008 * Basic Pin setup: * ------------ ---u---- * ARDUINO 13| OUT1 |1 28| OUT channel 0 * 12| OUT2 |2 27|-> GND (VPRG) * 11| OUT3 |3 26|-> SIN (pin 8) * 10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 7) * 9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9) * 8|-> SIN (pin 26) . |6 23|-> BLANK (pin 10) * 7|-> SCLK (pin 25) . |7 22|-> GND * 6| . |8 21|-> VCC (+5V) * 5| . |9 20|-> 2K Resistor -> GND * 4| . |10 19|-> +5V (DCPRG) * 3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3) * 2| . |12 17|-> SOUT * 1| . |13 16|-> XERR * 0| OUT14|14 15| OUT channel 15 * ------------ -------- * * - Put the longer leg (anode) of the LEDs in the +5V and the shorter leg (cathode) in OUT(0-15). * - +5V from Arduino -> TLC pin 21 and 19 (VCC and DCPRG) * - GND from Arduino -> TLC pin 22 and 27 (GND and VPRG) * - digital 3 -> TLC pin 18 (GSCLK) * - digital 7 -> TLC pin 25 (SCLK) * - digital 8 -> TLC pin 26 (SIN) * - digital 9 -> TLC pin 24 (XLAT) * - digital 10 -> TLC pin 23 (BLANK) * - The 2K resistor between TLC pin 20 and GND will let ~20mA through each LED. * * If you are daisy-chaining more than one TLC, connect the SOUT of the first TLC to * the SIN of the next. All the other pins should just be connected together: * BLANK of TLC1 -> BLANK of TLC2 -> ... * The one exception is that each TLC needs it's own resistor between pin 20 and GND. * * Alex Leone , 2008-10-31 */ /* These two includes should go at the top of any file that uses the library */ #include "tlc_config.h" #include "Tlc5940.h" //VARIABLES FOR STRETCH SENSOR/TRIGGER int switchPin = 2; // digital input pin for a switch int switchState = 0; // the state of the switch int stretchPin = 0; //Analog input pin that the stretch sensor is attached to int stretchValue = 0; //value read from the stretch sensor int count = 0; //count the number of times triggered is true int threshold = 575; // the threshold at which count is triggered boolean triggered = false; //boolean value triggered is set to false boolean doneCounting = false;//boolean value doneCounting is set to false //END TRIGGER VARIABLES //VARIABLES FOR LIGHTS int lightParent[4] = { 1,17,33,49};//assigning pins to an array of lightParents (lead LEDs) int lightChildren[12] = { 4,6,8,20,22,24,36,38,40,51,53,55};//assigning pins to an array of lightChildren (secondaryLEDs) int childPerParent = 3;//the number of lightChildren per parent int numTriggered = 0;//the number of times the stretch sensor has reached the trigger point (i.e. the number of lightParents that should be lit) int maxLight = 1000;//the brightest any given LED will get boolean litParents = false;//variable to check if parents are lit boolean finished = false;//variable to check if lightAnimation is finished unsigned long lastBulkChange = 0;//variable to keep track of time of last secondary LED group change //END LIGHT VARIABLES void setup() { pinMode(switchPin, INPUT);// set the switch pin to be an input /* Tlc.init() has to be called before using any of the library functions */ Tlc.init(); Serial.begin(9600); Tlc.clear();//clear all values for TLC Tlc.update();//update all values for TLC } void loop() { switchState = digitalRead(switchPin);// read the switch input if (switchState == 1) // if the switch is closed { numTriggered=count;//set numtriggered to equal the count from the stretch sensor if(!litParents)//if the lightParents are not lit { setParents();//call the setParents fuction delay(1000); if(!finished)//if the animation is not finished { for(int i=0;i= threshold && triggered){//if the stretch values is greater than or equal to the threshold and triggered boolean is true triggered = false;//change triggered to false Serial.println ("Trigger off");//print trigger off in debugger pane } delay (100);//wait 50 milliseconds before next loop } void setParents()//a function to set the lightParents' value { Tlc.clear();//clear value for the TLC for(int i=0;i= 0) //while the parents are brighter than 0 { Tlc.set(lightParent[family],parentValue);//set the parent of a given family to parentValue Tlc.update();//update TLC values delay(changeTime);//delay for changeTime milliseconds parentValue-=valueIncrement;//decrease the parentValue by valueIncrement Serial.println(parentValue);//print parentValue to the debugging pane } }