运行代码时遇到问题,例如“如果未在此范围内声明”

时间:2019-06-19 20:22:59

标签: arduino-uno

我得到一个错误,如果不在范围内

int亮度= 120; //开始时多少LED会亮

int fadeAmount = 10;

unsigned long currentTime;

无符号长loopTime;

const int pin_A = 19; //初始化编码器引脚A的引脚19

const int pin_B = 18; //初始化编码器引脚B的引脚18

int按钮= 28; //初始化按钮的插针28。

无符号字符编码器_A;

无符号字符编码器_B;

无符号字符编码器_A_prev = 0;

无效设置(){

pinMode(3,输出); //将引脚3声明为led的输出

pinMode(pin_A,INPUT); //将引脚19声明为输入

pinMode(pin_B,INPUT); //将引脚18声明为输入

currentTime = millis();

loopTime = currentTime;

}

无效循环(){

currentTime = millis(); //此命令将获取当前经过的时间

if(currentTime> =(loopTime + 5)){//距离编码器最后一次检查5毫秒= 200Hz

encoder_A = digitalRead ( pin_A ) ;                 // Reading the encoder pins

encoder_B = digitalRead ( pin_B ) ;                 // Reading the encoder pins

if ( ( !encoder_A ) && ( encoder_A_prev ) ) {

  // A has gone from high to low

  If ( encoder_B )  {                                  // encoder is moved clock wised so B is high

    If ( brightness + fadeAmount <= 255 ) brightness += fadeAmount ;    // This command will increase the brightness      

  }   

  else {

    // if encoder is moved counter-clockwise then b will be low     

    If( brightness - fadeAmount >= 0 ) brightness -= fadeAmount ;       // This will decrease the brightness

  }   

}   

encoder_A_prev = encoder_A ;                                                                            // this will Store value of A for next time   

analogWrite ( 3, brightness ) ;                                                                                  // This will set the brightness of pin 3:

loopTime = currentTime ;  

}

}

0 个答案:

没有答案