用户
 找回密码
 立即注册

QQ登录

只需一步,快速开始

点击进入授权页面

只需一步,快速开始

  • QQ空间
  • 回复
  • 收藏
  • TA的每日心情
    开心
    2018-5-25 14:48
  • 签到天数: 393 天

    [LV.9]以坛为家II

    本帖最后由 vickywong 于 2016-12-21 10:07 编辑

    我的在大赛专区的arduino计算器程序http://www.arduino.cn/thread-22827-1-1.html在arduino IDE1.6.5上运行正常,在IDE1.6.11和IDE1.6.13上编译上传后,1602屏幕上就不停地出1111111,一直不停。调了很长时间也没调好。请问各位大神程序哪里有BUG?怎么改才能在1.6.13上正常?
    在IDE1.6.13上单独测试4*4键盘也是读数错误,不是设想的按一个键显一个数,而是不停轮流显示第一行的位置,还偶尔停一下。

    代码在链接里:http://www.arduino.cn/thread-22827-1-1.html

    打赏作者鼓励一下!
    我建议你将上传的程序贴上来
    感谢支持,希望以上内容能给予你启发
    没有代码  看不出什么鬼
    打赏作者鼓励一下!
    在1.8.5上也这样
    [C++] 纯文本查看 复制代码
    #include <Keypad.h>
    #include <LiquidCrystal_I2C.h>
     
    LiquidCrystal_I2C lcd(0x27, 16, 2); 
     
    const byte ROWS = 4; 
    const byte COLS = 4; 
    char keys[ROWS][COLS] = {
    {'1','2','3','+'},
    {'4','5','6','-'},
    {'7','8','9','*'},
    {'C','0','=','/'}
    };
    
    byte rowPins[ROWS] = {8,9,10,11};
    byte colPins[COLS] = {4,5,6,7};
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
     
    // --------------------------------------------------------------------------------------------------------------------
    int dot = A0;
    int dotFlag = 0;
    int dotButton = 0;
    float num1, num2, fraction;
    float total;
    char operation, button;
    char input[16];
    int n = 1750;
    
    //-------------------------------------------------------------------------------------------------------------------------------
    
    void setup()
    {
      pinMode(dot, INPUT);
      Serial.begin(9600);
      lcd.init();
      lcd.backlight();
      lcd.clear();
      lcd.setCursor(3, 0);
      lcd.print("LOADING...");
      for (int i = 0; i < 16; i++)
      {
        lcd.setCursor(i, 1);
        lcd.write(255);
        delay(50);
      }
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print("Simple Arduino");
      lcd.setCursor(3, 1);
      lcd.print("Calculator");
      delay(n);
      lcd.clear();
    }
    
    //-----------------------------------------------------------------------
    
    void loop()
    {
      char customKey = keypad.getKey();
      if (customKey) {
        Serial.println(customKey);
      }
      while (1)
      {
        dotButton = digitalRead(dot);
        button = keypad.getKey();
        if (button == 'C')
        {
          dotFlag = 0;
          num1 = 0;
          num2 = 0;
          fraction = 0;
          total = 0;
          operation = 0;
          lcd.clear();
        }
        else if (dotButton == LOW)
        {
          dotFlag = 1;
        }
        else if (button >= '0' && button <= '9')
        {
          if (dotFlag == 0)
          {
            num1 = num1 * 10 + (button - '0');
            lcd.setCursor(0, 0);
            lcd.print(num1);
          }
          else if (dotFlag == 1)
          {
            fraction = (button - '0');
            num1 = num1 + (fraction / 10);
            lcd.setCursor(0, 0);
            lcd.print(num1);
            dotFlag++;
          }
          else if (dotFlag == 2)
          {
            fraction = (button - '0');
            num1 = num1 + (fraction / 100);
            lcd.setCursor(0, 0);
            lcd.print(num1);
            dotFlag++;
          }
        }
        else if (button == '-' || button == '+' || button == '*' || button == '/')
        {
          operation = button;
          dotFlag = 0;
          lcd.setCursor(15, 0);
          lcd.print(operation);
          break;
        }
      }
    
      while (1)
      {
        dotButton = digitalRead(dot);
        button = keypad.getKey();
        if (button == 'C')
        {
          dotFlag = 0;
          num1 = 0;
          num2 = 0;
          fraction = 0;
          total = 0;
          operation = 0;
          lcd.clear();
          break;
        }
        else if (dotButton == LOW)
        {
          dotFlag = 1;
        }
        else if (button >= '0' && button <= '9')
        {
          if (dotFlag == 0)
          {
            num2 = num2 * 10 + (button - '0');
            lcd.setCursor(0, 1);
            lcd.print(num2);
          }
          else if (dotFlag == 1)
          {
            fraction = (button - '0');
            num2 = num2 + (fraction / 10);
            lcd.setCursor(0, 1);
            lcd.print(num2);
            dotFlag++;
          }
          else if (dotFlag == 2)
          {
            fraction = (button - '0');
            num2 = num2 + (fraction / 100);
            lcd.setCursor(0, 1);
            lcd.print(num2);
            dotFlag++;
          }
        }
        if (button == '=')
        {
          domath();
          break;
        }
      }
      // Third while loop for ensuring C button is executed after while loop 2.
      while (1)
      {
        button = keypad.getKey();
        if (button == 'C')
        {
          dotFlag = 0;
          num1 = 0;
          num2 = 0;
          fraction = 0;
          total = 0;
          operation = 0;
          lcd.clear();
          break;
        }
      }
    }
    void domath()
    {
      switch (operation)
      {
        case '+':
          total = num1 + num2;
          break;
        case '-':
          total = num1 - num2;
          break;
        case '/':
          total = num1 / num2;
          break;
        case '*':
          total = num1 * num2;
          break;
      }
      lcd.print('=');
      lcd.clear();
      if (operation == '/' && num2 == 0)
      {
        lcd.print("ERROR 0 DIV");
      }
      else
      {
        lcd.print(total);
      }
    }

    这是从另一个帖子上抄的,我上传后可以运行
    发新帖
    发表评论
    高级模式  
    您需要登录后才可以回帖 登录 | 立即注册  
    关闭

    推荐主题 上一条 /2 下一条