我无法找到似乎匹配的此错误的解决方案 我对arduino非常陌生,我试图让一组5个LED点亮作为电位器
我正在编辑ifstatementconditional示例草图以实现此目的,但不断收到此错误
这里是代码
// These constants won't change:
const int analogPin = A1;
const int ledPins[5] = {
13, 12, 11, 10, 9 };
const int threshold = 1023;
const int section = threshold / 5;
const int pinCount = 5
void setup() {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED:
if (analogValue > section * 1) {
digitalWrite(ledPins[0], HIGH);
}
else{
digitalWrite(ledPins[0], LOW);
}
if (analogValue > section * 2) {
digitalWrite(ledPins[1], HIGH);
}
else{
digitalWrite(ledPins[1], LOW);
}
if (analogValue > section * 3) {
digitalWrite(ledPins[2], HIGH);
}
else{
digitalWrite(ledPins[2], LOW);
}
if (analogValue > section * 4) {
digitalWrite(ledPins[3], HIGH);
}
else{
digitalWrite(ledPins[3], LOW);
}
if (analogValue > section * 5) {
digitalWrite(ledPins[4], HIGH);
}
else{
digitalWrite(ledPins[4], LOW);
}
// print the analog value:
Serial.println(analogValue);
delay(1); // delay in between reads for stability
}
答案 0 :(得分:2)
可能是
中缺少的分号 const int pinCount = 5
答案 1 :(得分:0)
它的
const int ledPins[5] = {
13, 12, 11, 10, 9 };
只需拿出5分
const int ledPins[] = {
13, 12, 11, 10, 9 };
在C中,您无法在声明中指定数组的大小并为其指定默认值。如果您想为数组保留大小,稍后修改可以使用
int foo[5];