Multiple Analog Input Mapping Error..

Hello All,

I’ve been working on this sketch to map data from a flex sensor to a row of LEDs. Now, I’m trying to adapt the sketch to use two (and eventually more) sensors to map data in the same way, responding to their corresponding analog input across a row of LEDs. I’ve edited the sketch to use a second input but I keep getting a “too few arguments to function…” error and I’m not exactly sure how to identify and fix the problem.

Any suggestions? Thanks!

int flexPin = 0;
int flexPin2 = 1;
                  
void setup() {
  for (int i=10; i<21; i++){
    pinMode(i, OUTPUT);
  for (int i2=25; i2<36; i2++){
    pinMode(i2, OUTPUT);
  }
}
}

void loop(){
 for (int i=10; i<21; i++){
    digitalWrite(i, LOW);
 for (int i2=25; i<36; i2++){    
    digitalWrite(i2, LOW); 
  }
 } 
 
 int lightLevel = map(analogRead(flexPin), 175, 250, 10, 20);
 int lightLevel2 = map(analogRead(flexPin2), 175, 250, 25, 35); 
         
 int ledON = constrain(lightLevel, 10, 20);
 int ledON2 = constrain(lightLevel2, 25, 35);  
 
 blink(ledON, 10,1);
 blink(ledON2, 10,1);
}

void blink(int LEDPin, int LEDPin2, int onTime, int offTime){
  // Turn the LED on                                         
 digitalWrite(LEDPin, HIGH);
 digitalWrite(LEDPin2, HIGH);
 
 delay(onTime);
                                        
  digitalWrite(LEDPin, LOW);

  delay(offTime);
}

bug in the code, try this …

int flexPin = 0;
int flexPin2 = 1;
                  
void setup() 
{
  for (int i=10; i<21; i++) 
  {
    pinMode(i, OUTPUT);  // there was a closing } missing here, that's why I use this indentation 
  }

  for (int i2=25; i2<36; i2++)
  {
    pinMode(i2, OUTPUT);
  }
}

void loop()
{
 for (int i=10; i<21; i++)
 {
    digitalWrite(i, LOW);
 }
 for (int i2=25; i<36; i2++)
 {    
    digitalWrite(i2, LOW); 
 } 
 
 int lightLevel = map(analogRead(flexPin), 175, 250, 10, 20);
 int lightLevel2 = map(analogRead(flexPin2), 175, 250, 25, 35); 
         
 int ledON = constrain(lightLevel, 10, 20);
 int ledON2 = constrain(lightLevel2, 25, 35);  
 
 blink(ledON, ledON2,  10, 1);  // note that delays of 10 and especially 1 ms are hard to see 
}

void blink(int LEDPin, int LEDPin2, int onTime, int offTime){
  // Turn the LED on                                         
 digitalWrite(LEDPin, HIGH);
 digitalWrite(LEDPin2, HIGH);
 
 delay(onTime);
                                        
  digitalWrite(LEDPin, LOW);

  delay(offTime);
}

Check the reference / tutorial section for array’s - will make your sketch much simpler

bubbabrotha: I keep getting a "too few arguments to function.." error and I'm not exactly sure how to identify and fix the problem.

This is one of those cases where the complier is telling you the exact problem and exactly where to look.

too few arguments to function 'void blink(int, int, int, int)'

You declared "blink" with 4 arguments here:

bubbabrotha: void blink(int LEDPin, int LEDPin2, int onTime, int offTime){

But then when you call blink, you only give it 3 arguments, like here:

bubbabrotha: blink(ledON, 10,1); blink(ledON2, 10,1);

Thanks a million Rob and James! That helps clarify a lot.

I’m trying to add an on/off temporary state change button to the circuit so that the one switch will turn the entire circuit on and off. My issue now is how to digitally write HIGH and LOW values to the entire circuit as opposed to a single LED (Most examples I could find only use a single LED. I assume it’s the same principle but this sketch involves additional HIGH and LOW digital writing which makes it a little more confusing as to what to write HIGH and LOW and at what specific points).

This is the sketch I’ve updated but it’s gets a unclear in the void loop portion.

//Flex Sensor Pin (flexPin)
//the analog pin the Flex Sensor is connected to
const int buttonPin = XXXX; 
int flexPin = 0;
int flexPin2 = 1;
int buttonState = 0;

void setup() {
 pinMode(buttonPin, INPUT);
  for (int i=2; i<10; i++){
    pinMode(i, OUTPUT);
  for (int i2=25; i2<36; i2++){
    pinMode(i2, OUTPUT); //sets the led pins 28 to 36 to output
  }
}
}


void loop(){
 //Ensure to turn off ALL LEDs before continuing 

if (buttonState == HIGH) {    
    digitalWrite(XXXXX, HIGH);  
  }
  else {
    digitalWrite(XXXXX, LOW);
  }
  
 for (int i=2; i<10; i++){
    digitalWrite(i, LOW);
 for (int i2=25; i<36; i2++){    
    digitalWrite(i2, 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(flexPin), 175, 250, 2, 9);
 int lightLevel2 = map(analogRead(flexPin2), 175, 250, 25, 35); 
         
// Make sure the value is between 4 and 13, to turn on an LED
 int ledON = constrain(lightLevel, 2, 9);
 int ledON2 = constrain(lightLevel2, 25, 35);  
 
//Blink the LED on
 blink(ledON, 10,1);
 blink(ledON2, 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);
}

Thanks for the suggestions!

bubbabrotha:
My issue now is how to digitally write HIGH and LOW values to the entire circuit as opposed to a single LED

What is “the entire circuit”? If you have LEDs connected to more than one pin of the Arduino, you make more calls to digitalWrite().

bubbabrotha:

//Blink the LED on

blink(ledON, 10,1);
blink(ledON2, 10,1);
}
//…
void blink(int LEDPin, int onTime, int offTime){
//…
// The blink function - used to turn the LEDs on and off
void blink2(int LEDPin2, int onTime2, int offTime2){

Why do you have blink2? It’s exactly the same as blink(). You changed the names of the local variables, but that doesn’t matter.