the arduino and the breadboard
如果你看这张图,我需要每个LED在电位器的不同阶段打开。因此,当它处于第一阶段时,从左起的第一个LED应该打开并点亮,当电位器到达第二级时,第二个led应该打开并关闭前一个LED,依此类推。我需要这为所有5个LEDS的工作,他们中的每一个都应该单独打开和关闭。这就是我到目前为止所得到的。一个答案将不胜感激,请保持代码相当简单,有相当多的代码中的错误,请原谅我,因为我是新的。
提前感谢
 // C++ code
//
int redLED = 13; //Pin numbers for the LEDS<br>int blueLED = 12;
int blueLED = 12;
int whiteLED = 11;
int yellowLED = 10;
int greenLED = 9;
int potent = A5; 
int potentNum = 0;
void setup() {
  // put your setup code here, to run once:
pinMode(redLED, OUTPUT); //Recognize the LEDS as OUTPUT
pinMode(blueLED, OUTPUT);
pinMode(whiteLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
}
 Serial.begin(9600);   //Begin the Serial Moniter
pinMode(potent, INPUT);
}
  void loop() {
  // put your main code here, to run repeatedly:
  /*digitalWrite(redLED, HIGH); //Turn all the LEDS on
  digitalWrite(blueLED, HIGH);
  digitalWrite(whiteLED,HIGH);
  digitalWrite(yellowLED, HIGH);
  digitalWrite(greenLED, HIGH);*/
  potentNum = analogRead(potent);    // gets value from sensor
  Serial.println(potentNum);
     delay(300);
  }发布于 2021-05-31 22:10:08
根据从模拟端口读取的值设置端口HIGH或LOW,以打开或关闭LED。
例如:
void loop() {
  // put your main code here, to run repeatedly:
  potentNum = analogRead(potent);    // gets value from sensor
  Serial.println(potentNum);
  digitalWrite(redLED, potentNum >= 171 ? HIGH : LOW);
  digitalWrite(blueLED, potentNum >= 341 ? HIGH : LOW);
  digitalWrite(whiteLED,potentNum >= 512 ? HIGH : LOW);
  digitalWrite(yellowLED, potentNum >= 683 ? HIGH : LOW);
  digitalWrite(greenLED, potentNum >= 853 ? HIGH : LOW);
  delay(300);
}https://stackoverflow.com/questions/67775133
复制相似问题