Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino 使用键盘更新整数数组_Arduino - Fatal编程技术网

Arduino 使用键盘更新整数数组

Arduino 使用键盘更新整数数组,arduino,Arduino,我有一个全局声明的数组 int update() //funtion for updating { int i=0; lcd.clear(); lcd.print("Welcome"); while(1){ if(num=keypad.getKey()) // { a[i]=num; lcd.clear(); lcd.print('*'); i=i+1; if(i=

我有一个全局声明的数组

int update() //funtion for updating   
{
  int i=0;  
  lcd.clear();  
  lcd.print("Welcome");  
  while(1){  
    if(num=keypad.getKey())  //
    {
      a[i]=num;  
      lcd.clear();  
      lcd.print('*');  
      i=i+1;  
      if(i==4)   
        goto no;  
    }  
  }  
  no:  
  return 0;           
} 
我需要使用键盘输入来更新这个数组。我已经通过从我的void循环调用函数update完成了更新。但无论我做什么,我都不能更新它。怎么了


我是阿杜伊诺的新手。有人能建议怎么做吗。

如果不按任何键,keypad.getKey将返回什么?我假设在没有按下任何键的情况下,它将返回-1

a[]={1,2,2,3,4}

请始终确保正确的格式代码和文本,以便其他人能够真正理解和回答您的问题。永远记得在要求别人之前先做自己的工作。
int update() //funtion for updating   
{ 
    int i=0; //intialize i
    int num; //declare num
    lcd.clear();  
    lcd.print("Welcome");  
    while(1)
    {
        num=keypad.getKey();
        if(num != -1)  //Test if any button is pressed
        {
            a[i]=num;  
            lcd.clear();  
            lcd.print('*');  
            i=i+1;  
            if(i==4) return 0;
            delay(500); //delay so multiple values aren't added to array for single press     
        }
    }  
}