错误:“ <”令牌之前的预期主要表达式:arduino RGB跳舞灯

时间:2019-07-04 19:56:05

标签: c++ arduino

此代码无效。

尝试使用谷歌搜索(对C ++来说是较新的东西)

此代码用于根据从面包板上的声音传感器拾取的声音电平来更改引脚3、4、5上的功率电平。我已经用串行监视器检查了声级,似乎上面有正确的数字,所以我认为IF语句是错误的。

[code]
int DO = 2; //Pin for Digital Output - DO
int DA = A0; // Pin for Analog Output - AO
int threshold = 45; //Set minimum threshold for LED lit
int sensorvalue = 0;

void setup() {
//  Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
sensorvalue = analogRead(DA);  //Read the analog value
//  Serial.print("Analog: ");
//  Serial.print(sensorvalue);  //Print the analog value
//  Serial.print("  ");
//  Serial.print("Digital: ");
//  Serial.println(digitalRead(DO));  //Print the digital value

if (sensorvalue =< 40) {
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
}
if (sensorvalue =< 45) {
  digitalWrite(3, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
}
if (sensorvalue =< 50) {
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
}
else {
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
}
}

[/code]

Should leave no error.
Digital pins 3,4,5 should output the stated power level depending on the sound level from the sound sensor on the board.

1 个答案:

答案 0 :(得分:3)

这不是有效的c ++ operator =<

应更改为<=