Just get rid of i2 etc, and simply use i throughout
This worked. Thank you!!!!
//Flex Sensor Pin (flexPin)
//the analog pin the Flex Sensor is connected to
int flexPin1 = 0;
int flexPin2 = 1;
int flexPin3 = 2;
int flexPin4 = 3;
int flexPin5 = 4;
void setup() {
for (int i=2; i<9; i++){
pinMode(i, OUTPUT);
for (int i=9; i<16; i++){
pinMode(i, OUTPUT);
for (int i=16; i<23; i++){
pinMode(i, OUTPUT);
for (int i=23; i<30; i++){
pinMode(i, OUTPUT);
for (int i=30; i<37; i++){
pinMode(i, OUTPUT);
}
}
}
}
}
}
void loop(){
for (int i=2; i<9; i++)
{
digitalWrite(i, LOW);
}
for (int i2=9; i2<16; i2++)
{
digitalWrite(i2, LOW);
}
for (int i=16; i<23; i++)
{
digitalWrite(i, LOW);
}
for (int i=23; i<30; i++)
{
digitalWrite(i, LOW);
}
for (int i=30; i<37; i++)
{
digitalWrite(i, LOW);
}
/* Read the flex Level
Adjust the value 130 to 275 to span 28 to 36
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 lightLevel = map(analogRead(flexPin1), 175, 250, 2, 8);
int lightLevel2 = map(analogRead(flexPin2), 175, 250, 9, 15);
int lightLevel3 = map(analogRead(flexPin3), 175, 250, 16, 22);
int lightLevel4 = map(analogRead(flexPin4), 175, 250, 23, 29);
int lightLevel5 = map(analogRead(flexPin5), 175, 250, 30, 36);
// Make sure the value is between 4 and 13, to turn on an LED
int ledON = constrain(lightLevel, 2, 8);
int ledON2 = constrain(lightLevel2, 9, 15);
int ledON3 = constrain(lightLevel3, 16, 22);
int ledON4 = constrain(lightLevel4, 23, 29);
int ledON5 = constrain(lightLevel5, 30, 36);
//Blink the LED on
blink(ledON, 10,1);
blink(ledON2, 10,1);
blink(ledON3, 10,1);
blink(ledON4, 10,1);
blink(ledON5, 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);
// Delay so that you can see the LED go On.
delay(offTime);
}
// The blink function - used to turn the LEDs on and off
void blink2(int LEDPin2, int onTime2, int offTime2){
// Turn the LED on
digitalWrite(LEDPin2, HIGH);
// Delay so that you can see the LED go On.
delay(onTime2);
// Turn the LED Off
digitalWrite(LEDPin2, LOW);
// Delay so that you can see the LED go On.
delay(offTime2);
}
// The blink function - used to turn the LEDs on and off
void blink3(int LEDPin3, int onTime3, int offTime3){
// Turn the LED on
digitalWrite(LEDPin3, HIGH);
// Delay so that you can see the LED go On.
delay(onTime3);
// Turn the LED Off
digitalWrite(LEDPin3, LOW);
// Delay so that you can see the LED go On.
delay(offTime3);
}
// The blink function - used to turn the LEDs on and off
void blink4(int LEDPin4, int onTime4, int offTime4){
// Turn the LED on
digitalWrite(LEDPin4, HIGH);
// Delay so that you can see the LED go On.
delay(onTime4);
// Turn the LED Off
digitalWrite(LEDPin4, LOW);
// Delay so that you can see the LED go On.
delay(offTime4);
}
// The blink function - used to turn the LEDs on and off
void blink5(int LEDPin5, int onTime5, int offTime5){
// Turn the LED on
digitalWrite(LEDPin5, HIGH);
// Delay so that you can see the LED go On.
delay(onTime5);
// Turn the LED Off
digitalWrite(LEDPin5, LOW);
// Delay so that you can see the LED go On.
delay(offTime5);
}
I still don't see the emergency
Given the time I want to make sure there is a viable solution to a situation I cannot change...but I guess if you search hard enough there will always be one.
However the issue still remains of using a switch to turn the entire loop on and off. This is the clearest example of the situation that I have found but it doesn't account for several LEDs and additional digitalwrite's...
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Thanks you for your help!!