how to return the value to the global variable to be used?

Im facing a problem. I need to use the random no. generated in the void loop from randomseed() to be displayed on the LCD and also being store in array. I simply cant display the random no. in the LCD, all i get is a blank LCD screen. Ill comment on the code bellow:

int randNumber;
long randNumber1;
const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 2;
const int transmit_en_pin = 3;
LiquidCrystal lcd(9, 11, 7, 6, 5, 4);
void setup()
{
lcd.begin(16, 2);
lcd.clear();



  // initialize the pushbutton pin as an input:
pinMode(buttonPin80, INPUT); 
pinMode(led_pin, OUTPUT);

SetupRFDataTxnLink(transmit_pin, baudRate);
randomSeed(analogRead(0)); // generate a random no. if there is no analog input
}


void loop()
{

float outArray[RF_DATA_ARRAY_SIZE];//the ninumber fo elements that 
randNumber = random(0,255);              //here is where the randNumber are generated.        
randNumber1 = random(90,150);

    // read the state of the pushbutton value:
    buttonState1 = digitalRead(buttonPin80);

   // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:

    if (buttonState1 == HIGH) // if the button is pressed, send the generated no. to the transmitter.
  { 
    outArray[0] = randNumber;               // Here is where the randNumber       generated from the void loop
      outArray[1] = randNumber1;
      outArray[2] = 80;
      outArray[3] = 0;
      union RFData outDataSeq;
      EncodeRFData(outArray, outDataSeq); 
      TransmitRFData(outDataSeq);
      lcd.setCursor(0, 0);
      lcd.print(randNumber);                  // Here is where i need the randomNumber for

You have not posted a complete program so the problem could be in the other part.

Can you get it work with the Serial Monitor rather than the LCD ?

Your outArray is a local variable and will be re-initialized at every iteration of loop(). Perhaps that is the problem. Maybe it should be a global variable or should be defined as a static local variable.

…R

how can i store the data in the array to a global variable? here is the code for the program.

#include <DataCoder.h>
#include <VirtualWire.h>
#include <LiquidCrystal.h>
const int buttonPin80 = 8;// the number of the pushbutton pin
int buttonState1 = 0;         // variable for reading the pushbutton status
const int baudRate = 9600;
int randNumber;
long randNumber1;
int dd;
const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 2;
const int transmit_en_pin = 3;
LiquidCrystal lcd(9, 11, 7, 6, 5, 4);
void setup()
{
    lcd.begin(16, 2);
    lcd.clear();
   
    
   
   // initialize the pushbutton pin as an input:
    pinMode(buttonPin80, INPUT); 
    pinMode(led_pin, OUTPUT);
    
    SetupRFDataTxnLink(transmit_pin, baudRate);
    randomSeed(analogRead(0)); // generate a random no. if there is no analog input
}


void loop()
{
  
    float outArray[RF_DATA_ARRAY_SIZE];//the ninumber fo elements that 
  randNumber = random(0,255);              //here is where the randNumber are generated.        
  randNumber1 = random(90,150);
 
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin80);
   
   // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
 
 if (buttonState1 == HIGH) // if the button is pressed, send the generated no. to the transmitter.
  { 
  outArray[0] = randNumber;               // Here is where the randNumber generated from the void loop
  outArray[1] = randNumber1;
  outArray[2] = 80;
  outArray[3] = 0;
  union RFData outDataSeq;
  EncodeRFData(outArray, outDataSeq); 
  TransmitRFData(outDataSeq);
  lcd.setCursor(0, 0);
  lcd.print(randNumber);                  // Here is where i need the randomNumber for
  digitalWrite(led_pin, HIGH);
  delay(100);
  digitalWrite(led_pin,LOW);
  delay(200);
  
 }
 else{
  outArray[0] = randNumber;
  outArray[1] = 80;
  union RFData outDataSeq;

  EncodeRFData(outArray, outDataSeq); 
  TransmitRFData(outDataSeq);  
  //digitalWrite(led_pin, HIGH);
  //delay(100);
  //digitalWrite(led_pin,LOW);
  //delay(100);
 }
  
  
    
  
  
}

Looks quite okay...

But have you tried to print anything else to the LCD?

Have you tried (like suggested before) to just print it to the serial monitor?

To put the array in global scope:

void loop()
{ 
    float outArray[RF_DATA_ARRAY_SIZE];//the ninumber fo elements that

use

float outArray[RF_DATA_ARRAY_SIZE];//the ninumber fo elements that

void loop()
{

Google "C++ variable scope". But I see that reply #3 says that it might not be your problem.

Can i like store the generated randNumber in a globle variable to be used? becasue the array is to store the number in the randomNumber generated using Random().

calvin1030: Can i like store the generated randNumber in a globle variable to be used?

Yes

...R

Robin2: Yes

...R

I've tried whole day, but couldn't solve, could you help me to modify my code or point me out how could I achieve that, is that the problem with too much type variable assigning?

Maybe you need to explain a bit better what you want to do.

And you need to start answering the questions we ask you ;) See post #3

In the code on line 35 you already store the random value in a global variable. So I don't see the problem....

calvin1030:
I’ve tried whole day, but couldn’t solve, could you help me to modify my code

You need to post the latest version of your program so we are on the same page as you are.

…R