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
the keyword to my question is that can i constantly generate a randNumber that store in a global variables to be used in anywhere in this sketch? thanks for helping
Aucun commentaire:
Enregistrer un commentaire