【发布时间】:2019-10-10 22:58:07
【问题描述】:
我的代码有什么问题?我不断得到
需要左值作为赋值的左操作数
我正在尝试用 2 个按钮构建一个 SR latch,如果按下两个按钮,LED 应该处于低电平。如果它们中的任何一个被按下,LED 应该能够一直亮着,直到它被另一个按钮重置
#include <arduinio.h>
const int buttonPin[] = {2,3}; // the number of the pushbutton pins
const int ledPin = 4; // the number of the LED pin
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// initialize the pushbutton pin as an input:
pinMode(2,INPUT);
pinMode(3,INPUT);
}
void loop(){
buttonState1 = digitalRead (2);
buttonState2 = digitalRead (3);
Serial.println(buttonState1);
Serial.println(buttonState2);
if (buttonState1 = 1 && buttonState2 = 0) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else if (buttonState1 = 0 && buttonState2 = 1) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else if (buttonState1 = 0 && buttonState2 = 0) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED on:
digitalWrite(ledPin, LOW);
}
}
【问题讨论】:
标签: c++ arduino arduino-uno arduino-ide arduino-c++