read integers in an array and display it on a 16x2 lcd, help

Can someone help me? it is urgent :frowning:
I want to save 5 whole numbers and display them on a 16x2 lcd screen. I only get a 0. This is what I have:

#include <LiquidCrystal.h> 
LiquidCrystal lcd (12,11,5,4,3,2);
int array1[5];
void setup(){
  Serial.begin(9600);
  for(int i=0; i<4; i++){
  array1[i];
}
 for(int j=0;j<4;j++){
   lcd.setCursor(0,0);
    lcd.print(array1[j]);
  }
}
void loop(){
 
}

Nothing in that code ever puts anything into the array which is why you can't get anything out of it.

I'd sort of expect 'array[1];' to have a '= something" in there.

Steve

what I want is for the user to enter integer data

is it possible to do that?

  for(int i=0; i<4; i++){

array1[i];
}

This does not do anything (except for wasting cpu cycles :wink: )

To get a value in the array, use e.g.

  for(int i=0; i<4; i++){
  array1[i] = i;
}

Not quite what you want but it's a start

 for(int j=0;j<4;j++){

lcd.setCursor(0,0);
    lcd.print(array1[j]);
  }

This will at high speed display the values in the array at position 0,0; your eye will probably not be able to follow and only see the last number displayed.

is it possible to do that?

Yes. How is the user going to enter the numbers? Keypad, serial port, ... ?

Example 4 of Robin2's serial tutorial shows how to read in an integer from the monitor (although you didn't say if input is from the monitor or elsewhere).

In fact, even better than example 4, is example 5, and enter one line as <int,int,int,int,int>

// 5 integers into an array
// BASED ON Example 5 - Receive with start- and end-markers combined with parsing
//  https://forum.arduino.cc/index.php?topic=396450

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // temporary array for use when parsing

// variables to hold the parsed data
int integerFromPC[5];

boolean newData = false;

//============

void setup() {
  Serial.begin(9600);
  Serial.println("Enter 5 integers in this style <int,int,int,int,int>  ");
  Serial.println();
}

//============

void loop() {
  recvWithStartEndMarkers();
  if (newData == true) {
    strcpy(tempChars, receivedChars);
    // this temporary copy is necessary to protect the original data
    //   because strtok() used in parseData() replaces the commas with \0
    parseData();
    showParsedData();
    newData = false;
  }
}

//============

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

//============

void parseData() {      // split the data into its parts

  char * strtokIndx; // this is used by strtok() as an index

  strtokIndx = strtok(tempChars, ",");     // get the first integer
  integerFromPC[0] = atoi(strtokIndx);     // convert this part to an integer
  for (byte i = 1; i < 5; i++)
  {
    strtokIndx = strtok(NULL, ","); //  get the second and subsequent integer
    integerFromPC[i] = atoi(strtokIndx);     // convert this part to an integer
  }
}

//============

void showParsedData() {
  Serial.print("Array values: ");
  for (byte i = 0; i < 5; i++)
  {
    Serial.print(integerFromPC[i]); Serial.print(" ");
  }
  Serial.println(" ");
}

PcArduino123:
what I want is for the user to enter integer data

Where exactly do you expect that the user will enter this data. I'm sure you've seen an Arduino, it doesn't have anything that a user can type into.

Steve

Please, don't cross post thread

https://forum.arduino.cc/index.php?topic=653120.0

1 day to think about rules.