简体   繁体   English

Arduino无法根据模拟输入变量点亮LED

[英]Arduino cannot light up led based on analog input variable

I cant make arduino output high using a variable for example I declare this above my function 我无法使用变量将arduino输出调高,例如我在函数上方声明了这一点

int pin;  
pinMode(A1, OUTPUT);

Main function 主功能

 if(id ==2){
 pin = A1;
 ledlight();}
 if(id==3){
  pin  =A2; 
 ledlight();} 

And after that i call this to light up my LED 之后,我叫它点亮我的LED

  void ledlight(){
  if (temp < 27 ) {

  digitalWrite(pin, HIGH);  
   }
   }

Surprisingly the led does not light up, when i replace it with A1 the led lighted up ,what is the problem ? 令人惊讶的是,led灯没有点亮,当我将其替换为A1时,led灯点亮了,这是什么问题?

use Serial to debug your program 使用串口调试程序

output every variable(id temp pin), then you will find out the answer 输出每个变量(id temp引脚),然后您会找到答案

here is the example of Serial 这是串行的示例

void setup() {
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(3, digitalRead(2));
  int n = analogRead(A0);
  Serial.print("analogRead from A0:");
  Serial.print(n);
  Serial.print("\n");
  delay(100);
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM