i'm trying to use multiple flex sensors with LED's. according to the bent, one of the LED will be on and the others are off. i tested for one sensor and it works fine. but i don't know how to turn it for multiple sensors. any one have an idea please ?
that's my code for one sensore
//Flex Sensor Pin (flexPin)
int flexPin = A0;
void setup() {
for (int i = 4; i < 13; i++) {
pinMode(i, OUTPUT); //sets the led pins 4 to 13 to output
Serial.begin(9600);
}
}
void loop() {
//Ensure to turn off ALL LEDs before continuing
for (int i = 4; i < 13; i++) {
digitalWrite(i, LOW);
}
// Read the flex Level
int flexReading = map(analogRead(flexPin), 400, 755, 4, 12);
// Make sure the value does not go beyond 4 or 13
int LEDnum = constrain(flexReading, 4, 12);
/*Call the blink function: this will turn the LED on for 10 milliseconds, and keep it
off for only 1 millisecond. 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);
Serial.print("Flex Value = ");
Serial.println(analogRead(flexPin));
// Increase if you want to see an actual blinking effect.
delay(offTime);
}
void setup() {
Serial.begin(9600);
for (int i = 4; i < 13; i++) {
pinMode(i, OUTPUT); //sets the led pins 4 to 12 to output
}
}
void loop() {
//Ensure to turn off ALL LEDs before continuing
for (int i = 4; i < 13; i++) {
digitalWrite(i, LOW);
}
for (int flexPin = A0; flexPin <= A5; flexPin++) {
// Read the flex Level
int flexValue = analogRead(flexPin);
Serial.print("Flex Value = ");
Serial.println(flexValue);
int flexReading = map(flexValue, 400, 755, 4, 12);
// Make sure the value does not go beyond 4 or 12
int LEDnum = constrain(flexReading, 4, 12);
/*Call the blink function: this will turn the LED on for 10 milliseconds, and keep it
off for only 1 millisecond. 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 if you want to see an actual blinking effect.
delay(offTime);
}