Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/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
C++ 需要在arduino上电位计的不同电平上打开不同的LED_C++_Arduino_Led - Fatal编程技术网

C++ 需要在arduino上电位计的不同电平上打开不同的LED

C++ 需要在arduino上电位计的不同电平上打开不同的LED,c++,arduino,led,C++,Arduino,Led,如果你看图片,我需要每个LED在电位计的不同阶段打开。因此,当它处于第一阶段时,左边的第一个LED应该打开并点亮,当电位计达到第二级时,第二个LED应该打开并关闭前一个LED,依此类推。我需要这5个LED都工作,每个LED都应该分别打开和关闭。这就是我目前得到的。一个答案将不胜感激,请保持代码相当简单,有相当多的代码中的错误,请原谅我,因为我是新的这个 提前谢谢 // C++ code // int redLED = 13; //Pin numbers for the LEDS<br&g

如果你看图片,我需要每个LED在电位计的不同阶段打开。因此,当它处于第一阶段时,左边的第一个LED应该打开并点亮,当电位计达到第二级时,第二个LED应该打开并关闭前一个LED,依此类推。我需要这5个LED都工作,每个LED都应该分别打开和关闭。这就是我目前得到的。一个答案将不胜感激,请保持代码相当简单,有相当多的代码中的错误,请原谅我,因为我是新的这个

提前谢谢

 // 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);
  }
<代码> /C++代码 // int redLED=13//LED的管脚编号
int blueLED=12; int蓝色发光二极管=12; int-whiteLED=11; int黄色发光二极管=10; int绿色发光=9; int=A5; int-potennum=0; 无效设置(){ //将安装代码放在此处,以便运行一次: pinMode(红色发光二极管,输出);//将发光二极管识别为输出 引脚模式(蓝色LED,输出); pinMode(白色,输出); 引脚模式(黄色LED,输出); 引脚模式(绿色LED,输出); } Serial.begin(9600)//开始串行监视器 pinMode(有效输入); } void循环(){ //将主代码放在此处,以便重复运行: /*digitalWrite(红色LED,高);//打开所有LED 数码写入(蓝色,高亮度); 数字写入(白色,高); 数码写入(黄色,高); 数码写入(绿色,高)*/ potentNum=analogRead(有效);//从传感器获取值 Serial.println(potennum); 延迟(300); }
根据从模拟端口读取的值设置端口
,以打开或关闭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);
}

这是我学校的一个项目,相信我,我已经尝试了几种不同的代码,所有这些代码都返回了一个错误请参见[关于家庭作业]