Variable not declared in scope

I am writing this to find the pinout to a 4 by 3 keypad. I am very new to arduino so I am not exactly sure what is wrong.

//keypad Pinout

int val1 = 0; int val2 = 0; int val3 = 0; int val4 = 0; int val5 = 0; int val6 = 0; int val7 = 0;

void setup() { Serial.begin(9600); pinMode(1,INPUT); pinMode(2,INPUT); pinMode(3,INPUT); pinMode(4,INPUT); pinMode(5,INPUT); pinMode(6,INPUT); pinMode(7,INPUT); }

void loop() { va11 = digitalRead(1); va12 = digitalRead(2); va13 = digitalRead(3); va14 = digitalRead(4); va15 = digitalRead(5); va16 = digitalRead(6); va17 = digitalRead(7); if ((val1==HIGH) || (val2==HIGH) || (val3==HIGH) || (val4==HIGH) || (val5==HIGH) || (val6==HIGH) || (val7==HIGH)) { Serial.println(val1,val2,val3,val4,val5,val6,val7); } }

This is the error message I get:

sketch_mar30a.cpp: In function 'void loop()': sketch_mar30a:24: error: 'va11' was not declared in this scope sketch_mar30a:25: error: 'va12' was not declared in this scope sketch_mar30a:26: error: 'va13' was not declared in this scope sketch_mar30a:27: error: 'va14' was not declared in this scope sketch_mar30a:28: error: 'va15' was not declared in this scope sketch_mar30a:29: error: 'va16' was not declared in this scope sketch_mar30a:30: error: 'va17' was not declared in this scope sketch_mar30a:33: error: no matching function for call to 'HardwareSerial::println(int&, int&, int&, int&, int&, int&, int&)' C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:54: note: candidates are: void Print::println(const String&) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:55: note: void Print::println(const char*) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:56: note: void Print::println(char, int) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:57: note: void Print::println(unsigned char, int) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:58: note: void Print::println(int, int) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:59: note: void Print::println(unsigned int, int) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:60: note: void Print::println(long int, int) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:61: note: void Print::println(long unsigned int, int) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:62: note: void Print::println(double, int) C:\Users\Sree\Desktop\arduino-0022\hardware\arduino\cores\arduino/Print.h:63: note: void Print::println()


va11 = digitalRead(1);
  va12 = digitalRead(2);
  va13 = digitalRead(3);
  va14 = digitalRead(4);
  va15 = digitalRead(5);
  va16 = digitalRead(6);
  va17 = digitalRead(7);


val1 = digitalRead(1); val2 = digitalRead(2); val3 = digitalRead(3); val4 = digitalRead(4); val5 = digitalRead(5); val6 = digitalRead(6); val7 = digitalRead(7);

Yes, the C/C++ compiler is really that picky. It works on what you type in, not what you meant to type in. :D


In other words spell 'val' with a letter l not a digit 1...

Also you can't use print or println with lots of values - the print library has to be tiny.

You can be much more concise with the boolean expression in the 'if':

  if ((val1==HIGH) || (val2==HIGH) || (val3==HIGH) || (val4==HIGH) || (val5==HIGH) || (val6==HIGH) || (val7==HIGH))
  if (val1 || val2 || val3 || val4 || val5 || val6 || val7)

HIGH is treated as true and LOW as false.


You can’t use pin 1 and Serial at the same time, either.