Dezember 9, 2011
Introduction // The goal for our approach to creating a light table was to make it as simple and intuitive as possible. That anyone could approach the interface and withought labelling would understand how they could play and interact with the lightbox. Another important factor to us was to keep it as simple as possible. Concept // The project started by creating an interface. The interface had to fulfill the following; It allows the user to create colors in two different modes. RGB & HSB. More info on the requirements here. We decided on a buttom up approach for the interface. At the bottom and with a large switch the user could turn the lightbox On and switch between the RGB & HSB modes. Using a switch also gives instant feedback on which mode the user is in. Above the switch are two bottons which instantly give the user a "white" color and the other is to show the "complimentary" color of the currently displayed color. So the user can compare and contrast the two. Clicking on the complementary color botton again return the user to the displayed color. These two switches are found above the switch as they are fixed modes. In the middle of the light table is the main part of the interface. There are three large dials that are color coded to give a visual feedback to the user. The dials each has a LED display that shows what value the dials currently has assigned to it. The dials are infinite dials which was a requirement as values are recalled from the memory. Once the dial has reached its max or min value of 255 or 0 respectively you can still turn the dial but the visual feedback from the color under the dial an d the LED display remain the same. This is a great way to tune the user to react to colors. The dials are logically assigned (Dial 1 / RGB Mode (Red) HSB Mode (Color) , Dial 2 / RGB Mode (Green) HSB Mode (Saturation) , Dial 3 / RGB Mode (Blue) HSB Mode (Brightness). Finally the three bottoms at the top of the interface are memory buttons. They are used to save and recall values. Clicking and holding the memory button for two seconds saves the color. The user sees that a color is saved because a RGB LED is lit directly next to the botton with the saved color. When you have a color saved and you are playing with another color on the color dials clicking on the memory value causes a fade effect from the color values on the color dials to the saved color. If the value on the color dial is a saved color for example memory 1 and you click on memory 2, there is a hard cut to the memory 2 color. That way colors saved in the memory can be compared better because they do now have a fade. Materials // The materials we used where plexi glass and aluminum. The arched aluminum bride is the body of the light box. All the elements should be attached to the arched aluminum bridge. The curved plexi glass bottom is simply a cover for all the electronics and its curved body should make the lightbox pleasing to lift and handle. The dials and switch are made of aluminum as are the bottons. This gives the lightbox a clean and neutral look. Also because everything is uniform the user is much more attuned with the colors being displayed on the lightbox interface. Suggestions & Feedback // The lightbox will undergo some changes before we release it. The feedback we recieved was to consider; 1: A opening near the LED that shows the user the light that the lightbox emits in its neutral form. The lightbox will display light onto colorful surfaces so the user needs to know what the color looks like on a white surface. The DJ lightbox group had an elegant solution for this problem which we will most likely integrate in our lightbox. 2: The aluminum is very shiny and reflective at the moment. We will need to find another surface solution to make it less reflective. 3: The color of our Lightbox should be considered. The old Lightbox had a grey color which was a good contrast to the colorful surfaces used with the lightbox. Maybe we should consider making a similiar color. Code //// Libraries --------------------------------------------------------- #include <Wire.h> // #include <HPRGB2.h> // RGB Led Library #include <NewSoftSerial.h> #include <RGBConverter.h> // Instance of HPRGB Object ------------------------------------------ HPRGB ledShield; // default mcp4728 id(0) and default PCA9685 id(0) RGBConverter rgbc; // rgb to Hsv and Hsv to Rgb converter library (https://github.com/ratkins/RGBConverter) // Pin definitions --------------------------------------------------- // define the pins for buttons and switches #define BUT1 4 #define BUT2 11 //multiplexer Pin definitions --------------------- #define MP1 7 // PinSelector pins #define MP2 6 // PinSelector Pins #define MP3 5// pinSelector Pins #define MPANALOG 0 // Common Output (Z) - Multiplexer ListenPin (recieves and sends Values) //RGB Button LED's //RGB Button LED's #define SDI 12 #define CKI 3 #define STRIP_LENGTH 9 // NUmber of LEDs on this strip <---- adjust here long input0 = 0; long input1 = 0; long input2 = 0; long strip_colors[STRIP_LENGTH]; // create array // Variables --------------------------------------------------------- boolean rgbState = true; // RGB or HSB boolean complState = false; boolean whiteState = false; boolean wertAus1 = false; boolean wertAus2 = false; boolean wertAus3 =false; boolean rgbhsv = false; boolean complement = false; double hsv[]= { 0,0,0}; byte rgb[]= { 0,0,0}; int fadeint = 20; long timestamp = 0; int Delay = 500; long timestamp2 = 0; int Delay2 = 500; int Delay3 = 500; long timestamp3 = 0; // long mt = 0; int dt = 1500; // int value1 = 0; int value2 = 0; int value3 = 0; int potiValue = 0; int oldNumber[3] = { 0,0,0}; // global Variable for saving the old Numbervalue int withNumber[3] = { 0,0,0}; boolean button1 = false; boolean button2 = false; boolean button3 = false; boolean fade = false; boolean fade2 = false; boolean fade3 = false; int i = 3; NewSoftSerial mySerial(2, 8); // define Rx Tx Pins NewSoftSerial mySerial2(1, 9); NewSoftSerial mySerial3(0, 10); byte count = 0; // conter byte decimals[4]; // decimals array byte decimals2[4]; byte decimals3[4]; int drehPoti1[2] = { 0,1}; // pin numbers (multiplexer!) of the first wheel int drehPoti2[2] = { 2,3}; // pin numbers (multiplexer!) of the second wheel int drehPoti3[2] = { 4,5}; // pin numbers (multiplexer!) of the third wheel int counter = 0; int dcm = 14; // counter until saved boolean memoryBT = false; // int counter2 = 0; int dcm2 = 14; // counter until saved boolean memoryBT2 = false; // int counter3 = 0; int dcm3 = 14; // counter until saved boolean memoryBT3 = false; // 6x6 Array - memories[buttonNr][0 = Red, 1 =Green, 2=Blue, 3=Hue, 4=Ssaturation, 5 =Value/Brightness] -- all Values are 0-2047!!!!! int memories[3][6] = { { 2047,0,0,0,2047,2047 } , // Red { 0,2047,0,682,2047,2047 } , // Green { 0,0,2047,1365,2047,2047 } // Blue }; void setup() { ledShield.begin(); ledShield.setCurrent(350,350,350); // set maximum current for channel 1-3 (mA) ledShield.setFreq(600 ); // operation frequency of the LED driver (KHz) ledShield.eepromWrite(); // write current settings to EEPROM delay(100); // wait for EEPROM writing Serial.begin(9600); Serial.println("start"); // between arduino and computer mySerial.begin(9600); // setup software serial communication delay(100); // between arduino and 7 segment display mySerial.print(0x76); // reset the 7 segment display // mySerial2.begin(9600); delay(100); mySerial2.print(0x76); mySerial3.begin(9600); delay(100); mySerial3.print(0x76); // Define Selection Pins as Output pinMode(MP1, OUTPUT); pinMode(MP2, OUTPUT); pinMode(MP3, OUTPUT); pinMode(SDI, OUTPUT); pinMode(CKI, OUTPUT); // pinMode(BUT1, INPUT); digitalWrite(BUT1, HIGH); // pinMode(BUT2, INPUT); digitalWrite(BUT2, HIGH); // analogWrite(1,1023); analogWrite(2,1023); analogWrite(3,1023); } // Loop ------------------------------------------------------------- void loop() { value1 = rgbControl(rgbState,0,drehPoti1); // (only to 255, potnumber, YellwoPinNumber, BluePinNumber) value1 = map(value1,0,2047,0,255); value2 = rgbControl(true,1,drehPoti2); // rgb stat e allways to true because in HSB only the hue ist endless. value2 = map(value2,0,2047,0,255); value3 = rgbControl(true,2,drehPoti3); // rgb stat e allways to true because in HSB only the hue ist endless. value3 = map(value3,0,2047,0,255); /*Serial.print("Value 1: "); Serial.print(value1); Serial.print("\t"); Serial.print("Value 2: "); Serial.print(value2); Serial.print("\t"); Serial.print("Value 3: "); Serial.print(value3); Serial.print("\t"); Serial.println();*/ //Serial.println(oldNumber[0]); if (rgbState == true){ // we are in rgb mode ledShield.goToRGB(value1, value2, value3); } if (rgbState == false) { // we are in hsb mode ledShield.goToHSB(value1, value2, value3); } //komplementär if(digitalRead(BUT1) == LOW && complState == false && millis()-timestamp >=Delay) { complement = true; button1 = button2 = button3 = false; fade = fade2= fade3 = false; timestamp = millis(); } //weiss if(digitalRead(BUT2) == LOW && whiteState == false && millis()-timestamp2 >=Delay2) { whiteState=true; button1 = button2 = button3 = false; fade = fade2= fade3 = false; withNumber[0] = oldNumber[0]; withNumber[1] = oldNumber[1]; withNumber[2] = oldNumber[2]; oldNumber[0]= 2047; oldNumber[1]= 2047; oldNumber[2]= 2047; timestamp2 = millis(); } if(digitalRead(BUT2) == LOW && whiteState == true && millis()-timestamp2 >=Delay2) { whiteState=false; button1 = button2 = button3 = false; fade = fade2= fade3 = false; oldNumber[0]= withNumber[0]; oldNumber[1]= withNumber[1]; oldNumber[2]= withNumber[2]; timestamp2 = millis(); } //Memory Save if(analogRead(1) > 1000 && memoryBT==false) { memoryBT3 =true; memoryBT2 =true; Serial.println("Button red"); Serial.println(counter); Serial.println(dcm); if(counter <= dcm){ // dcm = counter until saved counter++; Serial.println(counter); } } else{ if(counter > 2 && memoryBT==false){ //Serial.println("--- BT Memory aus ---"); memoryBT =true; memoryBT3 =false; memoryBT2 =false; button1 = true; if(counter >= dcm && memoryBT ==true){ Serial.println("--- safe ---"); button1 = button2 = button3 = false; fade = fade2= fade3 = false; if(rgbState){ // if current colormode = RGB memories[0][0]=oldNumber[0]; // Red memories[0][1]=oldNumber[1]; // Green memories[0][2]= oldNumber[2]; // Blue rgbc.rgbToHsv(oldNumber[0]/2047.0*255.0,oldNumber[1]/2047.0*255.0,oldNumber[2]/2047.0*255.0,hsv); // convert to HSV memories[0][3]=int(hsv[0]*2047); // hue memories[0][4]=int(hsv[1]*2047); // saturation memories[0][5]= int(hsv[2]*2047); //Value/Brightness memoryBT=false; counter = 0; } else { // if current colormode = HSV memories[0][3]=oldNumber[0]; //Hue memories[0][4]=oldNumber[1]; //Saturation memories[0][5]= oldNumber[2]; //Value/Brightness rgbc.hsvToRgb(oldNumber[0]/2047.0,oldNumber[1]/2047.0,oldNumber[2]/2047.0,rgb); memories[0][0]=rgb[0]*(2047/255); //Red memories[0][1]=rgb[1]*(2047/255); //Green memories[0][2]= rgb[2]*(2047/255); //Blue memoryBT=false; counter = 0; } //whiteState = false; } else if(counter < dcm && memoryBT ==true){ if(rgbState){ if( button1 == true ){ if(button3 == false && button2==false){ Serial.println("drinFade"); fade = true; fade2 = false; fade3 = false; } else{ Serial.println("keinFade"); fade = fade2= fade3 = false; oldNumber[0]= memories[0][0]; //Red oldNumber[1]= memories[0][1]; //Green oldNumber[2]= memories[0][2]; //Blue } } memoryBT=false; counter = 0; } else { oldNumber[0]= memories[0][3]; // Hue oldNumber[1]= memories[0][4]; // Saturation oldNumber[2]= memories[0][5]; // value/Brightness memoryBT=false; counter = 0; } // Serial.print(" loaded!"); //whiteState = false; } } } /* if(analogRead(2) > 1000 && memoryBT2==false) { memoryBT3 =true; memoryBT =true; Serial.println("Button green"); if(counter2 <= dcm2){ // dcm = counter until saved counter2++; Serial.println(counter2); } } else{ if(counter2 > 2 && memoryBT2==false){ //Serial.println("--- BT Memory aus ---"); memoryBT2 =true; memoryBT3 =false; memoryBT =false; button2 = true; if(counter2 >= dcm2 && memoryBT2 ==true){ Serial.println("--- safe ---"); button1 = button2 = button3 = false; fade = fade2= fade3 = false; if(rgbState){ // if current colormode = RGB memories[1][0]=oldNumber[0]; // Red memories[1][1]=oldNumber[1]; // Green memories[1][2]= oldNumber[2]; // Blue rgbc.rgbToHsv(oldNumber[0]/2047.0*255.0,oldNumber[1]/2047.0*255.0,oldNumber[2]/2047.0*255.0,hsv); // convert to HSV memories[1][3]=int(hsv[0]*2047); // hue memories[1][4]=int(hsv[1]*2047); // saturation memories[1][5]= int(hsv[2]*2047); //Value/Brightness memoryBT2=false; counter2 = 0; } else { // if current colormode = HSV memories[1][3]=oldNumber[0]; //Hue memories[1][4]=oldNumber[1]; //Saturation memories[1][5]= oldNumber[2]; //Value/Brightness rgbc.hsvToRgb(oldNumber[0]/2047.0,oldNumber[1]/2047.0,oldNumber[2]/2047.0,rgb); memories[1][0]=rgb[0]*(2047/255); //Red memories[1][1]=rgb[1]*(2047/255); //Green memories[1][2]= rgb[2]*(2047/255); //Blue memoryBT2=false; counter2 = 0; } //whiteState = false; } else if(counter2 < dcm2 && memoryBT2 ==true){ if(rgbState){ if( button2 == true ){ if(button1 == false && button3==false){ Serial.println("drinFade"); fade2 = true; fade = false; fade3 = false; } else{ Serial.println("keinFade"); fade = fade2= fade3 = false; oldNumber[0]= memories[1][0]; //Red oldNumber[1]= memories[1][1]; //Green oldNumber[2]= memories[1][2]; //Blue } } memoryBT2=false; counter2 = 0; } else { oldNumber[0]= memories[1][3]; // Hue oldNumber[1]= memories[1][4]; // Saturation oldNumber[2]= memories[1][5]; // value/Brightness memoryBT2=false; counter2 = 0; } // Serial.print(" loaded!"); //whiteState = false; } } } */ if(analogRead(3) > 1000 && memoryBT3==false) { memoryBT2 =true; memoryBT =true; Serial.println("Button blue"); if(counter3 <= dcm3){ // dcm = counter until saved counter3++; Serial.println(counter3); } } else{ if(counter3 > 2 && memoryBT3==false){ Serial.println("--- BT Memory aus 3 ---"); memoryBT3 =true; memoryBT2 =false; memoryBT =false; button3 = true; if(counter3 >= dcm3 && memoryBT3 ==true){ Serial.println("--- safe ---"); button1 = button2 = button3 = false; fade = fade2= fade3 = false; if(rgbState){ // if current colormode = RGB memories[2][0]=oldNumber[0]; // Red memories[2][1]=oldNumber[1]; // Green memories[2][2]= oldNumber[2]; // Blue rgbc.rgbToHsv(oldNumber[0]/2047.0*255.0,oldNumber[1]/2047.0*255.0,oldNumber[2]/2047.0*255.0,hsv); // convert to HSV memories[2][3]=int(hsv[0]*2047); // hue memories[2][4]=int(hsv[1]*2047); // saturation memories[2][5]= int(hsv[2]*2047); //Value/Brightness memoryBT3=false; counter3 = 0; } else { // if current colormode = HSV memories[2][3]=oldNumber[0]; //Hue memories[2][4]=oldNumber[1]; //Saturation memories[2][5]= oldNumber[2]; //Value/Brightness rgbc.hsvToRgb(oldNumber[0]/2047.0,oldNumber[1]/2047.0,oldNumber[2]/2047.0,rgb); memories[2][0]=rgb[0]*(2047/255); //Red memories[2][1]=rgb[1]*(2047/255); //Green memories[2][2]= rgb[2]*(2047/255); //Blue memoryBT3=false; counter3 = 0; } //whiteState = false; } else if(counter3 < dcm3 && memoryBT3 ==true){ Serial.println("3"); if(rgbState){ if(button3 == true ){ if(button1 == false && button2==false){ Serial.println("drinFade"); fade3 = true; fade2 = false; fade = false; } else{ Serial.println("keinFade"); fade = fade2= fade3 = false; oldNumber[0]= memories[2][0]; //Red oldNumber[1]= memories[2][1]; //Green oldNumber[2]= memories[2][2]; //Blue } } memoryBT3=false; counter3 = 0; } else { oldNumber[0]= memories[2][3]; // Hue oldNumber[1]= memories[2][4]; // Saturation oldNumber[2]= memories[2][5]; // value/Brightness memoryBT3=false; counter3 = 0; } // Serial.print(" loaded!"); //whiteState = false; } } } if(fade ==true && fade2==false && fade3==false){ Serial.println("fade"); i = 0; } else if(fade2 == true && fade==false && fade3==false){ Serial.println("fade2"); i=1; } else if(fade3== true && fade==false && fade2==false){ Serial.println("fade3"); i=2; } if(i < 3){ if(oldNumber[0] > memories[i][0]){ oldNumber[0] = oldNumber[0] -fadeint; } else if(0 > oldNumber[0] < memories[i][0]){ oldNumber[0] = oldNumber[0] +fadeint; } if(oldNumber[1] > memories[i][1]){ oldNumber[1] = oldNumber[1] -fadeint; } else if(0 > oldNumber[1] < memories[i][1]){ oldNumber[1] = oldNumber[1] +fadeint; } if(oldNumber[2] > memories[i][2]){ oldNumber[2] = oldNumber[2] - fadeint; } else if(0 > oldNumber[0] < memories[i][2]){ oldNumber[2] = oldNumber[2] +fadeint; } if(oldNumber[0] == (memories[i][0]+fadeint) || oldNumber[0] == memories[i][0] ) { wertAus1 = true; Serial.print("wertAus1"); } if(oldNumber[1] == (memories[i][1]+fadeint) || oldNumber[1] == memories[i][1] ) { wertAus2 = true; Serial.print("wertAus2"); } if(oldNumber[2] == (memories[i][2]+fadeint) || oldNumber[2] == memories[i][2] ) { wertAus3 = true; Serial.print("wertAus3"); } if(wertAus1 == true && wertAus2 ==true && wertAus3 == true){ i = 6; fade = false; fade2 = false; fade3 = false; wertAus1 = false; wertAus2 = false; wertAus3 = false; Serial.println("fade aus"); Serial.println(i); } } if (rgbState)// check if RGB { if (rgbhsv)// if first time change to rgb { rgbhsv = false; Serial.println("first rgb"); rgbc.hsvToRgb(value1/255.0,value2/255.0,value3/255.0,rgb); value1 = int(rgb[0]); value2 =int(rgb[1]); value3 = int(rgb[2]); oldNumber[0]=map(rgb[0],0,255,0,2047); oldNumber[1]=map(rgb[1],0,255,0,2047); oldNumber[2]=map(rgb[2],0,255,0,2047); } if (complement){ // check if first time to complementary complement = !complement; Serial.println("first complement rgb"); // complementary hue value oldNumber[0]=map(255-value1,0,255,0,2047); oldNumber[1]=map(255-value2,0,255,0,2047); oldNumber[2]=map(255-value3,0,255,0,2047); } } else // not RGB so its HSV 😉 { if (!rgbhsv)// check if first time change to hsv { rgbhsv = true; Serial.println("first HSV"); rgbc.rgbToHsv(value1,value2,value3,hsv); value1 = int((double)hsv[0]*360.0); value2 =int((double)hsv[1]*100.0); value3 = int((double)hsv[2]*100.0); oldNumber[0]=int(map(value1,0,360,0,2047)); oldNumber[1]=int(map(value2,0,100,0,2047)); oldNumber[2]=int(map(value3,0,100,0,2047)); } if(complement) // check if first time to complementary { complement = !complement; Serial.println("first complement hsv"); if (value1 <=180) { value1 = value1 + 180; } else { value1 = value1 - 180; } oldNumber[0]=int(map(value1,0,360,0,2047)); oldNumber[1]=int(map(value2,0,100,0,2047)); oldNumber[2]=int(map(value3,0,100,0,2047)); } } //Serial.println(); calculateDigits(value1, decimals); showDigits(decimals); calculateDigits(value2, decimals2); showDigits2(decimals2); calculateDigits(value3, decimals3); showDigits3(decimals3); // for(int i=0; i< STRIP_LENGTH; i++){ if(i<2){ input0 = (oldNumber[0])/2047.0*255.0; // R input1 = (0); // G input2 = (0); // B } else if(2 < i > 5){ input0 = (0); // R input1 = (oldNumber[1])/2047.0*255.0; // G input2 = (0); // B } else if(4 < i > 7){ input0 = (0);// R input1 = (0); // G input2 = (oldNumber[2])/2047.0*255.0; // B } else{ input0 = (memories[i][0])/2047.0*255.0; // R input1 = (memories[i][1])/2047.0*255.0; // G input2 = (memories[i][2])/2047.0*255.0; // B } long color = (long)input0 << 16 | (long)input1 << 8 | (long)input2; // bit shifted to one r g b value strip_colors[i] = (long)color; } post_frame(); } //function void showDigits(byte pdata[]){ mySerial.print(pdata[0]); mySerial.print(pdata[1]); mySerial.print(pdata[2]); mySerial.print(pdata[3]); // } void showDigits2(byte pdata[]){ mySerial2.print(pdata[0]); mySerial2.print(pdata[1]); mySerial2.print(pdata[2]); mySerial2.print(pdata[3]); } void showDigits3(byte pdata[]){ mySerial3.print(pdata[0]); mySerial3.print(pdata[1]); mySerial3.print(pdata[2]); mySerial3.print(pdata[3]); } void calculateDigits(byte cnt, byte pdata[]){ pdata[0] = 0x78; // empty character pdata[1] = cnt /100; // 100 pdata[2] = (cnt /10) % 10; // divided by 10 modulo 10 pdata[3] = (cnt % 100) % 10; // modulo 100 modulo 10 } void post_frame (void) { //Each LED requires 24 bits of data //MSB: R7, R6, R5..., G7, G6..., B7, B6... B0 //Once the 24 bits have been delivered, the IC immediately relays these bits to its neighbor //Pulling the clock low for 500us or more causes the IC to post the data. for(int LED_number = 0 ; LED_number < STRIP_LENGTH ; LED_number++) { long this_led_color = strip_colors[LED_number]; //24 bits of color data for(byte color_bit = 23 ; color_bit != 255 ; color_bit--) { //Feed color bit 23 first (red data MSB) digitalWrite(CKI, LOW); //Only change data when clock is low long mask = 1L << color_bit; //The 1'L' forces the 1 to start as a 32 bit number, otherwise it defaults to 16-bit. if(this_led_color & mask) digitalWrite(SDI, HIGH); else digitalWrite(SDI, LOW); digitalWrite(CKI, HIGH); //Data is latched when clock goes high } } //Pull clock low to put strip into reset/post mode digitalWrite(CKI, LOW); delayMicroseconds(500); //Wait for 500us to go into reset }
//global Variables int oldPy[3] = { 0,0,0}; // global Variable for saving the Values int oldPb[3] ={ 0,0,0}; // global Variable for saving the Values int rgbControl(boolean only255, int potNumber, int* potPinNumber) // only255 set the maximum value to 255, Number of the pot, pin of the pot { int py = 0; // potentiometer with the yellow cable (also first Pot) int pb = 0; // potentiometer with the blue cable (also second Pot) int oldpy = 0; // old Value int oldpb = 0; // old Value int realPoti = 0; // Values for Serial-debug int number = 0; // Is the saved value of every potentiometer char* quadrant = ""; // Variable for Serial-Debug int multiplicator = 1; if (only255){ multiplicator = 2; } else { multiplicator = 1; }; // Get the oldpy = oldPy[potNumber]; oldpb = oldPb[potNumber]; number = oldNumber[potNumber]; // use the Multiplexer to read the analog values, py = multiplexer(potPinNumber[0]); pb = multiplexer(potPinNumber[1]); // smoothing py = 0.6 * oldpy + 0.4 * py; pb = 0.6 * oldpb + 0.4 * pb; if ((py != oldpy) || (pb != oldpb)) // if no value changed then do nothing { if ((py >256) && (py <768)) // if first pot ist in its good valuerange (becaus the pot has problems in the lowest and highest ranges) { if(pb > 511) // checks if the second pot ist bigger then 512 -> defines the quadrant { number += multiplicator*(oldpy - py); // calculates the diffrence, thats also the speed with wich the pot was moved quadrant = " 1st quarant"; // Serial debug } else if (pb < 511) { number -= multiplicator*(oldpy - py);// calculates the diffrence, thats also the speed with wich the pot was moved quadrant = " 3rd quarant";// Serial debug } realPoti = (oldpy - py);// Serial debug } else if ((pb > 256) && (pb <768)) { if(py > 511) { number -= multiplicator*(oldpb - pb); // calculates the diffrence, thats also the speed with wich the pot was moved quadrant = " 2nd quarant";// Serial debug } else if (py < 511) { number += multiplicator*(oldpb - pb); // calculates the diffrence, thats also the speed with wich the pot was moved quadrant = " 4th quarant";// Serial debug } realPoti = (oldpb - pb);// Serial debug } } // remap the values in 0-255 or in endless (255,0,1,....254,255,0,1...) if (only255){ if (number >= 2047){ number = 2047; } if (number <= 0){ number = 0; } } if(!only255) { if (number > 2047){ number = 0; } if (number < 0){ number = 2047; } } // Serial debug /*if (quadrant != "" ) { Serial.print("\t"); Serial.print(quadrant); Serial.print("\t"); Serial.print(py); Serial.print("\t"); Serial.print(pb); Serial.print("\t"); Serial.print(realPoti); Serial.print("\t"); Serial.print(number); Serial.print("\t"); Serial.print(rgb); Serial.println(); }*/ oldPy[potNumber] = py; // save the values to the Array for the next itteration oldPb[potNumber] = pb; // save the values to the Array for the next itteration oldNumber[potNumber] = number; // save the values to the Array for the next itteration return(number); // return the 255 Value for the rgb-LED }
int multiplexer(int outputnr) { int selectionPins[3]; int analogValue = 0; byte binCode = byte(outputnr); // Convert outputnumber in byte // read the last three bits of the number code (1 = HIGH, 0 = LOW) for the multiplexer pinSelection int value1 = bitRead(binCode,0); int value2 = bitRead(binCode,1); int value3 = bitRead(binCode,2); digitalWrite(MP1, value1); // Set Selection Pins to HIGH or LOW digitalWrite(MP2, value2); digitalWrite(MP3, value3); analogValue = analogRead(MPANALOG); return(analogValue); }Photos //