Arduino + processing + multiplexer project help

Heya guys!

So, I am struggling with my project because I cannot understand how multiplexer works. Basically, my project is about controlling RGB, hue, saturation and other options on image using pots. Although, it requires multiplexer as I need more than 6 analog inputs.The main thing, is that I don't understand how to describe inputs coming from multiplexer so I can use it in processing. Or maybe my code is completely wrong? Thanks for help!

RGB4Faster.pde (1.1 KB)

MUX_lnk.ino (1.13 KB)

You will probably get more help if you post your code in code tags. I, for one, don't want to download your code to my machine to view it.

Can you give us the part number of the multiplexer or a link to the data sheet?

Think of a multiplexer as just an address translator. {Hopefully you're familiar enough with binary number representation, if not, ask again or can just look that up}.

For example, 2 bits can address any 1 of 4 input positions and connected that to the output. The address would look something like the following:

Bit (pos)
1 0 Line Selected


0 0 0
0 1 1
1 0 2
1 1 3

So by switching the correct addressing bits, you can connect your desired input line to the output.

Alright, so I worked it out how to use the multiplexer, but now I am struggling with coding HSB ( hue, saturation, brightness). I got RGB working fine, but when I try adding brightness nothing works ;/
Any thoughts?

Arduino code

int r0 = 0;      
int r1 = 0;  // the three digital pins for the bits     
int r2 = 0;         
 
int  bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//list of binary values
 
void setup(){
 
  pinMode(2, OUTPUT);    // r0
  pinMode(3, OUTPUT);    // r1
  pinMode(4, OUTPUT);    // r2
 
  Serial.begin(9600); // fire up the serial 
}
 
  
void loop () {
   
 for (int count=0; count < 8; count++) { //loop through each channel, checking for a signal
    
   int row = bin[count]; //channel 5 = 5th element in the bin list -> 101 etc. 
    
   r0 = bitRead(row,0); //bitRead() -> parameter 1 = binary sequence, parameter 2 = which bit to read, starting from the right most bit
   r1 = bitRead(row,1); //channel 7 = 111, 1 = 2nd bit 
   r2 = bitRead(row,2); // third bit
 
   digitalWrite(2, r0); // send the bits to the digital pins 
   digitalWrite(3, r1);
   digitalWrite(4, r2);
       
  // Serial.print(count);
  // Serial.print(" ==== ");
   Serial.print(analogRead(0));
   Serial.print(",");
  //Serial.print(","); // after sending the binary sequence, the mux determines which channel to read from and sends it to this analog input
 
  // delay (1000); // time to read the values
    
 }
 Serial.print(analogRead(A1));
 //Serial.print(",");
 Serial.println();
 
 }

Processing code

import processing.serial.*;
 
 PImage img;
 int redValue = 0;        // red value
 int greenValue = 0;      // green value
 int blueValue = 0;       // blue value
 
 Serial myPort;
 
 void setup() {
 size(800, 800);
 img = loadImage("example.jpg"); 

 
 
 
 println(Serial.list());
 myPort = new Serial(this, Serial.list()[0], 9600);
 myPort.bufferUntil('\n');
 }
 
 void draw() {
   loadPixels();
   
   while (myPort.available() > 0){ 
   String inString = myPort.readStringUntil('\n');
    if(inString != null){
    inString = trim(inString);
 int[] colors = int(split(inString, ","));
   println(colors[0]+", "+colors[1]+", "+colors[2]+", "+colors[3]+", "+colors[4]+", "+colors[5]+", "+colors[6]+", "+colors[7]+", "+colors[8]);
    
 tint(map(colors[4], 0, 1023, 0, 255),map(colors[1], 0, 1023, 0, 255),map(colors[2], 0, 1023, 0, 255));
   image(img,0,0);

    for (int x = 0; x < img.width; x++ ) {
    for (int y = 0; y < img.height; y++ ) {

      // Calculate the 1D pixel location
      int loc = x + y*img.width;

      // Get the R,G,B values from image
      float r = red (img.pixels[loc]);
      float g = green (img.pixels[loc]);
      float b = blue (img.pixels[loc]);

      // We calculate a multiplier ranging from 0.0 to 8.0 based on mouseX position. 
      // That multiplier changes the RGB value of each pixel.      
      float adjustBrightness = ((float) colors[0] / width) * 8.0; 
      r *= adjustBrightness;
      g *= adjustBrightness;
      b *= adjustBrightness;

      // The RGB values are constrained between 0 and 255 before being set as a new color.      
      r = constrain(r,0,255); 
      g = constrain(g,0,255);
      b = constrain(b,0,255);

      // Make a new color and set pixel in the window
      color c = color(r,g,b);
      pixels[loc] = c;
    }
  }
    }
 }
 }