Avoid using global variables. It is hard to track what values are actually stored in them and are a possible source for errors.
If a program is not working as expected, you have to use a debugger to step through your code and watch the variables. If this is not possible on your Arduino, write the application first on a PC to test and debug it (reading input then from the keyboard).
You have a design / logic error:
Reading input consisting of multiple characters must be performed within a loop but you don't have such in your input routines.
It would be also simpler to write a function that reads a numeric input and returns that for all three values instead of providing three functions which would basically do the same:
int get_num_from_keypad()
{
int count = 0;
int value = 0;
char key;
char buf[9];
key = keypad.getKey();
while (key != NO_KEY)
{
Serial.print(key);
if (key == '#')
{
buf[count] = '\0';
value = atoi(buf);
break;
}
buf[count++] = key;
key = keypad.getKey();
}
return value;
}
Read about linked lists before trying to use them. They have to use dynamic memory allocation using
malloc()
or
calloc()
.
If you have a known maximum number of data to be entered, you can even avoid using a linked list and instead use an array of fixed size and a variable holding the number of recordsets:
int ref_count = 0;
References refs[MAX_REFS];
void loop()
{
if (ref_count < MAX_REFS)
{
refs[ref_count].referenceNumber = get_num_from_keypad();
refs[ref_count].SPEED = get_num_from_keypad();
refs[ref_count].STEPS = get_num_from_keypad();
ref_count++;
}
}
To display this list simply loop up to but excluding
ref_count
.
Note also that all upper case names should not be used for variables. It is recommended to use those exclusively for preprocessor definitions.
[EDIT]
Quote:
since there is no debugger in arduino can you recommand me one i can use
for the memory allocation, i don't know how to work with the arduino memory so i'm gonna test the array you proposed
As already suggested you can develop your program on a PC first using
getchar()
for the input and
printf()
for the output.
You are using C which provides the already mentioned
malloc()
and
calloc()
standard library functions. Just use them like on any other platform (besides the fact that the Arduino has not much memory and they will fail when requesting too much memory).
[/EDIT]