-4

Currently elements of array a1[2] are initialised in code but I want to pass this element of global variable array a1[2] from keypad as v1.

Here is my code:

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

unsigned int a1[2]={1,10}; //global variable
//unsigned int a1[2] = {1,v1} //not working
/.. 
keypad initialization
.../

void setup() {
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(1,1);
  lcd.print("Press # to GO");
  lcd.setCursor(0,0);
  lcd.print("Enter v1: ");
  v1 = GetNumber();
}

void loop() {
  ...
}

int GetNumber() {
   ...
   ....
  return num;
}
dda
  • 6,030
  • 2
  • 25
  • 34
sputnik20
  • 1
  • 1

1 Answers1

1
unsigned int a1[2] = {1,v1} //not working

Of course, v1 not yet defined. I think you want:

unsigned int a1[2] = {1,0}; 
unsigned int v1;

Then, below v1 = GetNumber(); add a1[2] = v1;.

I don't understand why a1 is an array, but then I don't understand your objective.

The block below doesn't seem to be part of anything.

return num;
}
dda
  • 6,030
  • 2
  • 25
  • 34
KC Tucker
  • 131
  • 2
  • 4