display and modify a list on ARDUINO

i want to create a list who contains a number undefined of reference composed of 8 numbers :

exemple :

28546455
95685615
55925555
59295525
etc…

these number can be entered via a keypad

each reference contains 2 parameters :

1.speed
2.steps

example:

28546455 → speed : 500
→ steps : 10000

95685615 → speed : 300
–>steps : 20000

etc…

i have no idea where these references are gonna be saved on the arduino and how i can display these reference on a lcd (16,2) and naviguate betwwen them

if anyone can direct me i’m thankful

here a prototype of my code :

#include "Reference.h"
#include <SPI.h>
#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd (9);

char clavier[9];
int counter =0;
int value;

const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS]={
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS]={8,7,6,5};
byte colPins[COLS]={4,3,2};

Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);

llist my_liste=NULL;

void setup() {
  // put your setup code here, to run once:
  
lcd.begin(16,2);

}

void loop() {
  // put your main code here, to run repeatedly:
  
displayListe(my_liste);
my_liste=addNewReference(my_liste,value);

}

llist addNewReference(llist liste, int value){
getValue();
reference* newReference = malloc(sizeof(reference));
newReference->referenceNumber = value;
newReference->next=NULL;

if (liste ==NULL){
  return newReference;
}else{
  reference* temp = liste;
  while (temp->next!=NULL){
    temp = temp->next;
  }
  temp->next=newReference;
    return liste;
  }
 }

void getValue(){
  char key = keypad.getKey();
  if (key!= NO_KEY){
    clavier[counter++]=key;
    clavier[counter]='\0';

    if (key== '*'){
      value = atoi(clavier);
      counter=0;
    }
  }
}

 void displayListe(llist liste){
  reference *tmp=liste;
  while (tmp!=NULL){
    lcd.print(tmp->referenceNumber);
    tmp=tmp-> next;
  }
 }

and this is Reference.h library :

#ifndef _REFERENCE_H_
#define _REFERENCE_H_

typedef struct reference reference;

struct reference {
  int referenceNumber;
  struct reference *next;
};

typedef reference *llist;

#endif

sef13:
each reference contains 2 parameters :

28546455 → speed : 500
→ steps : 10000

Does that mean that you want an item to have 3 things 28546455, 500, 1000

If so it sounds like you need to create a struct that describes the data and then create an array of the structs. Something like

struct DataStruct {
    long dataIndex;
    int speed;
    long steps;
}

DataStruct myArray[10];  // which creates space for 10 entries

Then you can refer to (say) the 6th entry in the array like this

Serial.println(myArray[5].speed;

Because the Arduino as a very limited amount of memory it is best to create an array big enough for the largest amount of data you will need rather than trying to allocate memory when the program is running.

…R

And to navigate in your list, you can use push buttons. There are many libraries available to help you handle them. One would be to go up in the list, the other to go down.

thank you,

i have one more question: if i enter the references with there parameters will they be saved on the arduino or will they be lost if i disconnect and then reconnect the arduino?

sef13:
thank you,

i have one more question: if i enter the references with there parameters will they be saved on the arduino or will they be lost if i disconnect and then reconnect the arduino?

That depends on how and where you save them

You could, for instance, save to EEPROM or an SD card and retrieve them if/when required

sef13:
i have one more question: if i enter the references with there parameters will they be saved on the arduino or will they be lost if i disconnect and then reconnect the arduino?

They will be lost unless you store them to permanent memory as suggested by @UKHeliBob.

...R

i made this program who is supposed to add a reference with steps and speed but it doesn’t work at all
am i missing something ?

#include "Reference.h"
#include <Keypad.h>

char keypad_referenceNumber[9];
char keypad_SPEED[4];
char keypad_STEPS[6];

int counter = 0;

const byte ROWS =4;
const byte COLS =3;

char keys[ROWS][COLS]={
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS]={8,7,6,5};
byte colPins[COLS]={4,3,2};

Keypad keypad = Keypad (makeKeymap(keys),rowPins,colPins,ROWS,COLS);

int data_referenceNumber;
int data_SPEED;
int data_STEPS;

List *myList;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
List *myList = initialisation();
}

void loop() {
  // put your main code here, to run repeatedly:
  
 getreferenceNumber();
 getSPEED();
 getSTEPS(); 
  
addNewReference(myList,data_referenceNumber,data_SPEED,data_STEPS);
displayList(myList);

}
void getreferenceNumber(){
  char key = keypad.getKey();
  if (key!=NO_KEY){
    keypad_referenceNumber[counter++]= key;
    keypad_referenceNumber[counter]= '\0';
    Serial.print(key);

    if (key == '#'){
      data_referenceNumber= atoi(keypad_referenceNumber);
      Serial.println(data_referenceNumber);
      counter = 0;
    }
  }
}

void getSPEED(){
  
   char key = keypad.getKey();
  if (key!=NO_KEY){
    keypad_SPEED[counter++]= key;
    keypad_SPEED[counter]= '\0';

    if (key == '#'){
      data_SPEED= atoi(keypad_SPEED);
      Serial.println(data_SPEED);
      counter = 0;
    }
  } 
}

void getSTEPS(){
   char key = keypad.getKey();
  if (key!=NO_KEY){
    keypad_STEPS[counter++]= key;
    keypad_STEPS[counter]= '\0';

    if (key == '#'){
      data_STEPS= atoi(keypad_STEPS);
      Serial.println(data_STEPS);
      counter = 0;
    }
  }
}

List *initialisation(){
  List *list;
  References *references;
  
  if (list == NULL || references == NULL){
exit (EXIT_FAILURE);
}

references->referenceNumber = 0;
references->SPEED = 0;
references->STEPS = 0;

references->next = NULL;
list->firstElement = references;

 return list;
};

// x : reference number
// y : speed
// z : steps

void addNewReference(List *list, int x, int y, int z){
  References *newReference;
  
  if (list == NULL || newReference == NULL){
    exit (EXIT_FAILURE);
  }
  newReference->referenceNumber = x;
  newReference->SPEED = y;
  newReference->STEPS = z;

  newReference->next = list->firstElement;
  
  list->firstElement = newReference;   
}

void displayList(List *list){
  if (list == NULL){
    exit (EXIT_FAILURE);
  }
  References *current = list->firstElement;

  while(current!=NULL){
    Serial.println(current->referenceNumber);
    Serial.println(current->SPEED);
    Serial.println(current->STEPS);
    
    current = current->next;
  }
  Serial.println("NULL");
}

biblio.“Reference.h”

#ifndef _REFERENCE_H_
#define _REFERENCE_H_

typedef struct References References;
struct References{ 
  int referenceNumber;
  int SPEED;
  int STEPS;  
  References *next;    
};

typedef struct List List;
struct List{
  References *firstElement; 
};

#endif

When you call getreferenceNumber() you get a single character from the keypad if one is available and add it to the keypad_referenceNumber array even if it is not a number.

Having got one character from the keypad you call the getSPEED() function and do something similar. Surely you should not stop calling getreferenceNumber() until entry of the number is complete and you should not add characters to the array unless they are between '0' and '9'

i made the counter to take a specific number of characters and since it's a keypad with numbers only i don't need to specifiy the numbers between 9 and 0,
i really don't get it :confused:

sef13:
i made the counter to take a specific number of characters and since it’s a keypad with numbers only i don’t need to specifiy the numbers between 9 and 0,
i really don’t get it :confused:

Numbers only, apart from the ‘*’ and ‘#’ that is

To read a series of characters into an array do something like this

if a character is available
  read the character
  if it is between '0' and '9' 
    add it to the array and increment the counter - check that the array bounds are not exceeded
    add the terminator to the array
  else
  if the character is '#'
    convert the array to an integer
  end if
end if

If you are not worried about stopping the Arduino doing anything else whilst the number is entered you can put the code in a while loop and exit when the number has been entered and converted

something like this :

char key = keypad.getKey();

if (key!=NO_KEY){
  if (key=='0' ||key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9'){
    
keypad_referenceNumber[counter++]=key;
keypad_referenceNumber[counter]='\0';

    else if (key=='#'){
      data_referenceNumber=atoi(keypad_referenceNumber);
      counter=0;
    }
   }
  }

i dont have any idea on how to check if the array bounds are not exceeded or the while loop you are talking about

Wouldn't it be a lot simpler to turn your logic on its head like this

if (key!=NO_KEY){
  if (key=='#'){
      data_referenceNumber=atoi(keypad_referenceNumber);
      counter=0;
    }

  else {
    keypad_referenceNumber[counter++]=key;
    keypad_referenceNumber[counter]='\0';
  }
}

...R

there is the '*' key which i didn't use

i want to use it to erase a character which i just entered, i'm still thinking of how to do it

sef13:
there is the '*' key which i didn't use

So add in (before the final ELSE)

else if (key=='*'){
   // leave it blank until you know what you want here
}

...R