#include<arduino.h>
const int Led1=3;
const int Led2=5;
const int swichtcPin=2;
void setup() {
// put your setup code here, to run once:
pinMode(Led1,OUTPUT);
pinMode(Led2,OUTPUT);
pinMode(swichtcPin,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int switchState;
switchState=digitalRead(swichtcPin);
if(switchState=HIGH){
Led1=HIGH;
Led2=LOW;
delay(300);
Led1=LOW;
Led2=HIGH;
}
else{
Led1=LOW;
Led2=HIGH;
}
}
出错原因
sketch_oct10a.ino: In function 'void loop()':
sketch_oct10a:19: error: assignment of read-only variable 'Led1'
sketch_oct10a:20: error: assignment of read-only variable 'Led2'
sketch_oct10a:22: error: assignment of read-only variable 'Led1'
sketch_oct10a:23: error: assignment of read-only variable 'Led2'
sketch_oct10a:27: error: assignment of read-only variable 'Led1'
sketch_oct10a:28: error: assignment of read-only variable 'Led2'
assignment of read-only variable 'Led1'
const int Led1=3;
const int Led2=5;
const int swichtcPin=2;
void setup() {
// put your setup code here, to run once:
pinMode(Led1,OUTPUT);
pinMode(Led2,OUTPUT);
pinMode(swichtcPin,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int switchState;
switchState=digitalRead(swichtcPin);
if(switchState=HIGH){
Led1=HIGH;
Led2=LOW;
delay(300);
Led1=LOW;
Led2=HIGH;
}
else{
Led1=LOW;
Led2=HIGH;
}
}
出错原因
sketch_oct10a.ino: In function 'void loop()':
sketch_oct10a:19: error: assignment of read-only variable 'Led1'
sketch_oct10a:20: error: assignment of read-only variable 'Led2'
sketch_oct10a:22: error: assignment of read-only variable 'Led1'
sketch_oct10a:23: error: assignment of read-only variable 'Led2'
sketch_oct10a:27: error: assignment of read-only variable 'Led1'
sketch_oct10a:28: error: assignment of read-only variable 'Led2'
assignment of read-only variable 'Led1'