I know this is a well trodden query but I have done everything suggested , the variable is declared before
the setup, 'mycode[3]' is apparently recognised but 'codein[3]' gives a 'not declared in this scope' error on the same line
It seems strange to accept one but not the other, any ideas?
its only a small sketch so i am attaching all of it:
sketch_nov29a.ino (484 Bytes)
The OP's code
// simpple sketch to learn loop ,if and arrays
/*---- int mycode[]= {1,0,6,6}---- */
/*--- int codein[]= {0,0,0,0}---- */
void setup()
{
Serial.begin(9600);
} // end setup
void loop()
{
for (int i = 1; i < 5; i = i + 1)
{
Serial.println ( i );
codein[3] = (codein[3] + 1);
mycode[3] = ( 3 );
delay(1000);
}
if ( mycode[3] = codein[3]) // here i get 'codein' not declared in this scope
{
Serial.println (mycode[3]);
}
}
Note how much easier it is to read and copy when in code tags
Here is the full error message from compiling your code
C:\Users\Bob\AppData\Local\Temp\arduino_modified_sketch_742970\sketch_nov30a.ino: In function 'void loop()':
sketch_nov30a:23:2: error: 'codein' was not declared in this scope
codein[3] = (codein[3]+1);mycode[3]=( 3 );
^~~~~~
C:\Users\Bob\AppData\Local\Temp\arduino_modified_sketch_742970\sketch_nov30a.ino:23:2: note: suggested alternative: 'popen'
codein[3] = (codein[3]+1);mycode[3]=( 3 );
^~~~~~
popen
sketch_nov30a:23:28: error: 'mycode' was not declared in this scope
codein[3] = (codein[3]+1);mycode[3]=( 3 );
^~~~~~
C:\Users\Bob\AppData\Local\Temp\arduino_modified_sketch_742970\sketch_nov30a.ino:23:28: note: suggested alternative: 'modf'
codein[3] = (codein[3]+1);mycode[3]=( 3 );
^~~~~~
modf
sketch_nov30a:26:9: error: 'mycode' was not declared in this scope
if ( mycode[3]= codein[3]) // here i get 'codein' not declared in this scope
^~~~~~
C:\Users\Bob\AppData\Local\Temp\arduino_modified_sketch_742970\sketch_nov30a.ino:26:9: note: suggested alternative: 'modf'
if ( mycode[3]= codein[3]) // here i get 'codein' not declared in this scope
^~~~~~
modf
sketch_nov30a:26:20: error: 'codein' was not declared in this scope
if ( mycode[3]= codein[3]) // here i get 'codein' not declared in this scope
^~~~~~
C:\Users\Bob\AppData\Local\Temp\arduino_modified_sketch_742970\sketch_nov30a.ino:26:20: note: suggested alternative: 'popen'
if ( mycode[3]= codein[3]) // here i get 'codein' not declared in this scope
^~~~~~
popen
exit status 1
'codein' was not declared in this scope
The declaration of codein is commented out in your code, so no wonder the compiler reports that it is not declared. If you uncomment its declaration and add the required semicolon then the compiler will complain that mycode is not declared
That works now, thanks. I dont pretend to understand most of your reply, and different lines, but what are the 'suggested alternatives' ie popen and modf? and where do they fit in?
incidentally I only put the /-- stuff in after reading one of the other replies to an earlier query which i took as the correct syntax.
Now to carry on playing & learning
I dont pretend to understand most of your reply,
What I quoted was the full error message from the IDE so not strictly my reply
I have no idea what popen or modf are but you can safely ignore the suggestion to use them instead of your variable names.
Now i have another' not declared 'problem, Im feeling I must be getting slow on entering my 80th decade! but have spent hours looking for an answer. Im trying to get a character input from a keypad using Keypad library.
I can find no way to actually get a character returned without a 'not declared error', ive commented on a lot of things, but not all by any means, that ive tried, without success. i'm sure the answer is simple, but I'm not finding the various help files on using libraries very helpful, although accept that its probably me being the problem!
sketch_dec03a.ino (536 Bytes)
You're 800 years old?
Being as old as Yoda doesn't excuse you from not posting your code.
Im trying to get a character input from a keypad using Keypad library.
i'm sure the answer is simple, but I'm not finding the various help files on using libraries very helpful, although accept that its probably me being the problem!
I think that when using an unfamiliar library it always helps to run the library example code. You find them in ide window. Files>Examples>LibraryName>example sketches
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
}
}
Yeah, okay frustration made me careless, 8th decade is old enough!! I did attach the sketch but will post it as per instructions, which I have now read!.
I have run the example quite a few times but there is no indication of how to return a valid character.
Sorry the sketch doesnt show as it should , but I used 'copy for forum' and this is how it pastes.
[code]
#include <Key.h>
#include <Keypad.h>
//char key = ""; // these all gave a warning: 'invalid conversion
//char getKey = "";
//char keypad = "";
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
// char key = keypad.getKey(); // gives a not declared error 'keypad'
char key = Keypad keypad.getKey // gives expected primary-expression befor 'keypad'
// Serial.println (key);
// Delay(5000);
}
I have run the example quite a few times but there is no indication of how to return a valid character.
keypad.getKey() returns a character.
Notice how all this library stuff is in the example before you get to
char key = keypad.getKey();
Your posted sketch does not use the library properly
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS
Thank you cattledog for that, Ive got it working now. I had assumed that all the declarations in Keypad would be sorted and declared by the compiler.
So if I include a library in a sketch I have to make all declarations shown in the example, prior to the 'void setup' line? If so it would be helpful if this was mentioned in the help resources available.
Unfortunately the compiler isn't a mind-reader. It has no way to know what you want to call the thing, what particular layout of keypad you're using, what pins you are going to connect it to etc. You have to give it some help.
The many libraries need different amounts of information from you to set them up e.g. Servo (and many others) only needs you to tell it what each of your servos will be called. You can tell what is required from either the documentation or by looking at the example programs provided with each library.
Steve