/////////////// CHARLIEPLEXING /////////////// #define PIN_CP_1 0 #define PIN_CP_2 1 #define PIN_CP_3 7 #define PIN_CP_4 6 // for the charlieplexing matrix calcultion below #define PIN_CONFIG 0 #define PIN_STATE 1 // amount of leds #define LED_NUM 12 /////////////// TEMPERATURE /////////////// // the value of the 'other' resistor #define Serie_resistor 1000 // Thermistor pin #define Thermistor_pin 3 int base_thermistor_value = 0; /////////////// IR /////////////// #define sensor 10 // Sensor output voltage #define IRled 11 int matrix[LED_NUM][2][4] = { // PIN_CONFIG PIN_STATE // 1 2 3 4 1 2 3 4 { { OUTPUT, OUTPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW } }, //0 - yellow { { OUTPUT, OUTPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW } }, //1 - white { { INPUT, OUTPUT, OUTPUT, INPUT }, { LOW, HIGH, LOW, LOW } }, //2 - blue { { INPUT, OUTPUT, OUTPUT, INPUT }, { LOW, LOW, HIGH, LOW } }, //3 - white { { INPUT, INPUT, OUTPUT, OUTPUT }, { LOW, LOW, HIGH, LOW } }, //4 - white { { INPUT, INPUT, OUTPUT, OUTPUT }, { LOW, LOW, LOW, HIGH } }, //5 - yellow { { OUTPUT, INPUT, OUTPUT, INPUT }, { HIGH, LOW, LOW, LOW } }, //6 - blue { { OUTPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, HIGH, LOW } }, //7 - orange { { INPUT, OUTPUT, INPUT, OUTPUT }, { LOW, HIGH, LOW, LOW } }, //8 - orange { { INPUT, OUTPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, HIGH } }, //9 - blue { { OUTPUT, INPUT, INPUT, OUTPUT }, { HIGH, LOW, LOW, LOW } }, //10 - RED { { OUTPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, HIGH } } //11 - RED }; /////////////// CHARLIEPLEXING FUNCTIONS /////////////// ////////////////////////////////////////////// void lightOn( int led ) { pinMode( PIN_CP_1, matrix[led][PIN_CONFIG][0] ); pinMode( PIN_CP_2, matrix[led][PIN_CONFIG][1] ); pinMode( PIN_CP_3, matrix[led][PIN_CONFIG][2] ); pinMode( PIN_CP_4, matrix[led][PIN_CONFIG][3] ); digitalWrite( PIN_CP_1, matrix[led][PIN_STATE][0] ); digitalWrite( PIN_CP_2, matrix[led][PIN_STATE][1] ); digitalWrite( PIN_CP_3, matrix[led][PIN_STATE][2] ); digitalWrite( PIN_CP_4, matrix[led][PIN_STATE][3] ); }//void lightOn //////////////////////////////////////////////// //Turn on all LEDs at one (seemingly) //void allLightOn() { //Seemingly all on //for(int l = 0; l < LED_NUM; l++) //int l = 0; // change this number to see just one led // { // lightOn(l);// change this number to see just one led // delay(1); // }//for l //}//void allLightOn ////////////////////////////////////////////// ////Make a LED run arounda circle //void roundCircleLight() { //// The "with-delay" option // for(int l = 0; l < LED_NUM; l++) { // lightOn(l); // delay( 1000 / LED_NUM ); // }//for l //}//void roundCircleLight //////////////////////////////////////////////// //Turn on all different colored LEDs separated on (seemingly) void bluelight() { //Seemingly all on //for(int l = 0; l < LED_NUM; l++) //int l = 1; // change this number to see just one led //{ lightOn(2); delay(1); lightOn(6); delay(1); lightOn(9); delay(1); //}//for l }//void bluelight void whitelight() { //Seemingly all on //for(int l = 0; l < LED_NUM; l++) //int l = 1; // change this number to see just one led //{ lightOn(1); delay(1); lightOn(3); delay(1); lightOn(4); delay(1); //}//for l }//void whitelight void yellowlight() { //Seemingly all on //for(int l = 0; l < LED_NUM; l++) //int l = 1; // change this number to see just one led //{ lightOn(0); delay(1); lightOn(5); delay(1); //}//for l }//void yellowlight void orangelight() { //Seemingly all on //for(int l = 0; l < LED_NUM; l++) //int l = 1; // change this number to see just one led //{ lightOn(7); delay(1); lightOn(8); delay(1); //}//for l }//void orangelight void redlight() { //Seemingly all on //for(int l = 0; l < LED_NUM; l++) //int l = 1; // change this number to see just one led //{ lightOn(10); delay(1); lightOn(11); delay(1); //}//for l }//void redlight void warmlight() { //one by one warm on //for(int l = 0; l < LED_NUM; l++) //int l = 1; // change this number to see just one led //{ lightOn(10); delay(10); lightOn(7); delay(10); lightOn(0); delay(10); lightOn(11); delay(10); lightOn(8); delay(10); lightOn(5); delay(10); //}//for l }//void warmlight ///////////////////////////////////// /////////////// SETUP /////////////// ///////////////////////////////////// void setup() { Serial.begin(9600); pinMode(sensor, INPUT); // sensor mode to reading pinMode (IRled, HIGH); //led mode always on pinMode (Thermistor_pin,INPUT); }//void setup //////////////////////////////////// /////////////// LOOP /////////////// //////////////////////////////////// void loop() { ////////////////////////////////////LED loop//////////////////////////////////// //roundCircleLight(); // the circle loop //allLightOn(); // all the 12 leds on ////seemingly 3 blue leds on (shorter delay because the loop is longer) // for(int l = 0; l < 300; l++) { // bluelight(); // } // //seemingly 3 white leds on (shorter delay because the loop is longer) // for(int l = 0; l < 300; l++) { // whitelight(); //} // //seemingly warm leds on (extra short delay because the loop is longer) // for(int l = 0; l < 150; l++) { // warmlight(); // } // // //seemingly 2 yellow leds on (longer delay because the loop is shorter) // for(int l = 0; l < 150; l++) { // yellowlight(); // } // //seemingly 2 orange leds on (longer delay because the loop is shorter) // for(int l = 0; l < 150; l++) { // orangelight(); // } // //seemingly 2 red leds on (longer delay because the loop is shorter) // for(int l = 0; l < 150; l++) { // redlight(); // } ////////////////////////////////////thermistor loop//////////////////////////////////// // float reading; int Thermistor_value = analogRead(Thermistor_pin) ; Serial.print("Thermistor Analog "); Serial.println(Thermistor_value); delay(0); // took the delay out since the led void already lasts 3 sec or so.. how do i calculate this? if(Thermistor_value > (base_thermistor_value + 1) || Thermistor_value < (base_thermistor_value - 1)) { //seemingly 2 yellow leds on (longer delay because the loop is shorter) for(int l = 0; l < 150; l++) { yellowlight(); } //seemingly 2 orange leds on (longer delay because the loop is shorter) for(int l = 0; l < 150; l++) { orangelight(); } //seemingly 2 red leds on (longer delay because the loop is shorter) for(int l = 0; l < 150; l++) { redlight(); } } //if else { //seemingly 3 blue leds on (shorter delay because the loop is longer) for(int l = 0; l < 300; l++) { bluelight(); } //seemingly 3 white leds on (shorter delay because the loop is longer) for(int l = 0; l < 300; l++) { whitelight(); } }//else ////////////////////////////////////IR loop//////////////////////////////////// // //Read irsensor: // //int irsensor_value = analogRead(sensor); // // Serial.print("IR Analog "); // Serial.println(irsensor_value); // delay(0); // took the delay out since the led void already lasts 3 sec or so.. how do i calculate this? //// the IR sensor seems to react random.. mostly stays at 0 but sometimes just jumps to values - it does react on proximity but not alwyays correct. // }//void loop