intensify/fade leds according to sensor input

I have 4 touch sensors, and 4 leds. The brightness of the leds can vary from 0-255. The touch sensors are either high 1 or low 0.

When sensor 1 is touched I want led 1 to slowly become brighter, and less 2, 3, 4 to dim.
When sensor 2 is touched I want led 2 to slowly become brighter, and leds 1, 3, 4 to dim.
When sensor 3 is touched I want led 3 to slowly become brighter, and leds 1, 2, 4 to dim.
When sensor 4 is touched I want led 4 to slowly become brighter, and leds 1, 2, 3 to dim.

When a sensor is released the leds should stay put in the specific brightness.

How should I program this?? I figured something like this, however my programming skills are a bit lacking.

 for (int i=0; i < 3; i++){  // Check what electrodes were pressed
      if(touched & (1<<i)){
 

        if(touchStates[i] == 0){
          //pin i was just touched
                
      // whilst these sensors are pressed led 1 should become brighter, the others should dim
		analogWrite(led1, brightness1);   
		analogWrite(led2, brightness2);  
		analogWrite(led3, brightness3);  
		analogWrite(led4, brightness4);  

		brightness1 ++;
		brightness2 --;	
		brightness3 --;
		brightness4 --;

  
        }

      
    }else if(touchStates[i] == 1){
          //pin i is still being touched
       }  
      
        touchStates[i] = 1;      
      }else{
        //no touch
          
       }
        
        touchStates[i] = 0;
      }
    
    }

mpr121_touch.ino (8.88 KB)

When sensor 1 is touched I want led 1 to slowly become brighter, and less 2, 3, 4 to dim.

This requirement is incomplete. What does "slowly" mean? One increment per millisecond? One increment per tenth of a second? One increment a week?

I figured something like this, however my programming skills are a bit lacking.

Does it do what you want? If not, what does it do, and how does that differ from what you want?

fixed it!

for (int i=0; i < 3; i++){  // Check what electrodes were pressed
      if(touched & (1<<i)){
      
        if(touchStates[i] == 0){
          //pin i was just touched
             // whilst these sensors are pressed led 1 should become brighter, the others should dim
    		//brightnessBlue = brightnessBlue + fadeAmount;
            switch(i) {
              case 0:  // buitenste sensor is gedrukt 
                       if(touchStates[1] == 1) { //hij komt van binnen naar  buiten
                          brightnessBlue = brightnessBlue - fadeAmount;
                          blueFull = false; 
                          Serial.println("Verlaagd... door 1"); 
                                             
                       } else {
                         if(blueFull) { /// de waarde van Blue = Maximaal, dus andere dimmen. 
                           brightnessRed = brightnessRed - fadeAmountSmall; 
                           brightnessGreen = brightnessGreen - fadeAmountSmall; 
                           brightnessWhite = brightnessWhite - fadeAmountSmall; 
                           Serial.println("Vol dus de rest verlagen met Small");
                           
                         } else {
                          brightnessBlue = brightnessBlue + fadeAmountSmall; //Hij wordt voor de eerste keer aangeraakt
                          Serial.println("Verhoogd... door 1 met Small"); 
                         }
                       }
                  break;
              case 1: // middelste sensor 
                        if(touchStates[0] == 1) { //hij komt van buiten naar  binne
                         if(blueFull) { /// de waarde van Blue = Maximaal, dus andere dimmen. 
                           brightnessRed = brightnessRed - fadeAmount; 
                           brightnessGreen = brightnessGreen - fadeAmount; 
                           brightnessWhite = brightnessWhite - fadeAmount; 
                           Serial.println("Vol dus de rest verlagen");
                           
                         } else {
                            brightnessBlue = brightnessBlue + fadeAmount;
                            Serial.println("Verhoogd ... door 2");   
                         }
                                              
                       }
                        if(touchStates[2] == 1) { //hij komt van Binnen naar  buiten
                          brightnessBlue = brightnessBlue - fadeAmount;
                          Serial.println("Verlaagd ... door 2"); 
                          blueFull = false; 
                                             
                       }
                  break;
               
               case 2: //binneste sensor
                       if(touchStates[1] == 1) { //hij komt van binnen naar  buiten
                         if(blueFull) { // blauw is vol, dus de rest verlagen. 
                           brightnessRed = brightnessRed - fadeAmount; 
                           brightnessGreen = brightnessGreen - fadeAmount; 
                           brightnessWhite = brightnessWhite - fadeAmount; 
                           Serial.println("Vol dus de rest verlagen");
                         } else {
                       
                            brightnessBlue = brightnessBlue + fadeAmount;
                            Serial.println("Verhoogd... door 3");    
                         }          
                       }  else {
                         if(blueFull) {
                             brightnessRed = brightnessRed - fadeAmountSmall; 
                             brightnessGreen = brightnessGreen - fadeAmountSmall; 
                             brightnessWhite = brightnessWhite - fadeAmountSmall; 
                             Serial.println("Vol dus de rest verlagen met Small");
                         } else {
                             brightnessBlue = brightnessBlue + fadeAmountSmall; //Hij wordt voor de eerste keer aangeraakt
                            Serial.println("Verhoogd... door 3 met Small"); 
                         }
                       }
                   break;         
                                                    
            }
            
              checkBrightnessLevels(); 
              setPWMPorts(); 
          
              

            Serial.print("BLUE nr: ");
            Serial.print(i);
            Serial.print(" Brigtness: ");
            Serial.println(brightnessBlue);    
        
        }else if(touchStates[i] == 1){
          //pin i is still being touched
         
  

        }  
      
        touchStates[i] = 1;      
      }else{
     
       //}
        
        touchStates[i] = 0;
      }
    
    }