Help with Flex Sensor

I'm attempting to create the Infinity Gauntlet for NY Comic Con and I would like to install 6 LED lights behind 6 3D printed gems. I'm trying to configure my Arduino to increase the brightness of the 6 LEDs when the flex sensor is bent and then have the LEDs turn off when the sensor is not bent. Does anyone have a code that I can use?

Thank you
ECastro

Does anyone have a code that I can use?

analogRead() to read the flex sensor pins.
analogWrite() to write to the LED pins.

That'll be $8 and two ice cold Coors.

My apologies, let me add a little more detail to my original post.
I have the flex sensor plugged in to Analog A0, and the LEDs are in pin 7-12. I've only just started to learn how to program the Arduino and with such little time left before NYCC I'm not sure I will be able to learn the coding quick enough to create it myself.

Thanks again,
ECastro

I'm trying to tweak this code to have the lights turn on when the sensor is bent. Currently when you bend the sensor the first light turns on, if you continue to bend it the first light goes off and the second goes on, then it moves the the third light. I want all the lights to be off, but once I bend the sensor I would like them to slowly get brighter until max brightness.

//Flex Sensor Pin (flexPin)
//the analog pin the Flex Sensor is connected to
int flexPin = 0;  
                  
void setup() {
  for (int i=7; i<14; i++){
    pinMode(i, OUTPUT); //sets the led pins 7 to 12 to output
  }
}

void loop(){
 //Ensure to turn off ALL LEDs before continuing 
 for (int i=4; i<14; i++){
    digitalWrite(i, LOW); 
  }
 
 /* Read the flex Level 
  Adjust the value 130 to 275 to span 4 to 13
  The values 130 and 275 may need to be widened to suit 
  the minimum and maximum flex levels being read by the 
  Analog pin */
 int flexReading = map(analogRead(flexPin), 130, 275, 7, 14); 
         
// Make sure the value does not go beyond 4 or 13
 int LEDnum = constrain(flexReading, 7, 14); 
 
/*Call the blink function: this will turn the LED on for 10 milliseconds, and keep it
  off for only 1 millisecond. You can change the blink rate by changing these values,
  however, I want a quick response time when the flex sensor bends, hence the small 
  values. LEDnum determines which LED gets turned on.*/
 blink(LEDnum, 10,1);
}

// The blink function - used to turn the LEDs on and off
void blink(int LEDPin, int onTime, int offTime){
  // Turn the LED on                                         
 digitalWrite(LEDPin, HIGH);  
 
  // Delay so that you can see the LED go On.
 delay(onTime);
 
  // Turn the LED Off                                         
  digitalWrite(LEDPin, LOW);  
 
 // Increase this Delay if you want to see an actual blinking effect.
  delay(offTime);
}

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

How to use this forum

one way is to lite up the LEDs one at a time as the flex sensor is bent, like this (untested)

byte ledPin[6] = {7,8,9,10,11,12};
int flexPin = A0;  

void setup() 
{
  for (byte i = 0; i < 6; i++)
  {
    pinMode(ledPin[i], OUTPUT); //sets the led pins 7 to 12 to output
  }
}
//
void loop()
{
  blink(map(analogRead(flexPin), 0, 1023, 1, 6)); // you have 6 leds
}
//
void blink(byte ledsLit)
{     
  for (byte i = 0; i < 6; i++)
 { 
   if (i <= ledsLit)  digitalWrite(ledPin[i], HIGH); 
   else digitalWrite(ledPin[i], LOW); 
 }
}

the other way would be to use PWM on pins 3,5,6,9,10 & 11 and affect their brightness with the bending of the sensor like this also untested:

byte ledPin[6] = {3,5,6,9,10,11};//UNO PWM pins
int flexPin = A0;  

void setup() 
{
}
//
void loop()
{
  blink(map(analogRead(flexPin), 0, 1023, 0, 255)); // you can change (0, 255) to something like (50,255) to affect the minimum briteness
}
//
void blink(byte briteness)
{     
  for (byte i = 0; i < 6; i++)
 { 
    analogWrite(ledPin[i], briteness);  
 }
}