/*--------------------------------RADICAL EVERYTHING--------------------------------------*/ /* SPRING 2010 ANGELA CHEN /*adapted from Alex Leone's basic LED example setup for the TLC5940 /* lighting : each TLC5940 driver runs 16 LEDs, 8 drivers total /* sensors: 4 sensors total, 1 each (IR detector) to control 2 drivers (32 LEDs) (currently using 1 potentiometer) /* mechanical: controls 3 solenoid valves /*-------------------------------------------LOOP-------------------------------------------*/ /* NUM_TLCS is defined in "tlc_config.h" in the library folder. /* After editing tlc_config.h for your setup, /* delete the Tlc5940.o file to save the changes. /*------------------------------------------------------------------------------------------*/ /*----------------------------------------LIBRARIES----------------------------------------*/ #include "Tlc5940.h" #include "tlc_fades.h" /*-----------------------------------------------------------------------------------------*/ /*----------------------------------------ARUDINO PINS--------------------------------------*/ //#define ANALOG_PIN 0 /*------------------------------------------------------------------------------------------*/ /*----------------------------------------VARIABLES----------------------------------------*/ const int ledGroup = 0; const int ledsPerGroup = 16; //control 16 LEDs at a time (for each driver) const int potPin = 0; //analog in 3 connected to the potentiometer int potValue = 0; //value returned from the potentiometer TLC_CHANNEL_TYPE channel; //const int transistorPin //initialize in setup /*-----------------------------------------------------------------------------------------*/ /*------------------------------------------SET-UP-----------------------------------------*/ void setup() { Tlc.init(); // Call Tlc.init() to setup the tlc // You can optionally pass an initial PWM value (0 - 4095) for all channels Serial.begin(9600); for (int transistorPin = 4; transistorPin < 7; transistorPin++) { // initialize the transistor pins as output: pinMode(transistorPin, OUTPUT); } } /*------------------------------------------------------------------------------------------*/ /*-------------------------------------------LOOP-------------------------------------------*/ /* NUM_TLCS is defined in "tlc_config.h" in the library folder. /* After editing tlc_config.h for your setup, /* delete the Tlc5940.o file to save the changes. /*------------------------------------------------------------------------------------------*/ void loop() { /*-------------------------------------MECHANICAL-------------------------------------------*/ potValue = analogRead(potPin); //read pot, convert it from 0-255 int range = map(potValue, 0, 1000, 0, 3); //map that to control each transistor switch: //0 is little to no activity //1 is low activity //2 is med activity //3 is high activity Serial.println("Range: "+range); //do something different depending on the range value: switch (range) { case 0: //level 0 (no activity) Serial.println("no activity"); for (int transistorPin = 4; transistorPin < 7; transistorPin++) { digitalWrite(transistorPin, LOW); } break; case 1: //level 1(valve 0 OPEN) Serial.println("low activity"); for (int transistorPin = 4; transistorPin < 5; transistorPin++) { digitalWrite(transistorPin, HIGH); //open valve delay(500); digitalWrite(transistorPin, LOW); //close valve delay(500); } break; case 2: //level 2(valve 0 + 1 OPEN) Serial.println("medium activity"); for (int transistorPin = 4; transistorPin < 6; transistorPin++) { digitalWrite(transistorPin, HIGH); //digitalWrite(transistorPin, HIGH); delay(500); digitalWrite(transistorPin, LOW); delay(500); } break; // case 3: //level 3(valve 0,1,2 OPEN) Serial.println("high activity"); for (int transistorPin = 4; transistorPin < 7; transistorPin++) { // digitalWrite(transistorPin, HIGH); digitalWrite(transistorPin, HIGH); delay(500); digitalWrite(transistorPin, LOW); delay(500); } break; } /*--------------------------------------------------------------------------------*/ /*---------------------------------LIGHTING---------------------------------------*/ if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 23) { //The default fade buffer length (24). //how many leds to fade at a time if (!tlc_isFading(channel)) { //uint16_t duration = analogRead(0) * 4; //analogRead pin 0 uint16_t duration = 1000; //how long to stay on before fading int maxBrightness = analogRead(0); //pot value determines brightness value uint32_t startMillis = millis()+50; uint32_t endMillis = startMillis + duration; //higher the value = longer the duration of the fade tlc_addFade(channel, 0, maxBrightness, startMillis, endMillis); //increase brightness for LED next in array // tlc_addFade(channel, maxBrightness, 0, endMillis, endMillis + duration); //decreasing in brightness } if (channel++ == NUM_TLCS * 16) { //when it gets to the end of the loop channel = 0; //reset } } tlc_updateFades(); } /*------------------------------------------------------------------------------------------*/