我试着制造一个振动检测仪,并遵循了制造商的指导,在那里我购买了Arduino,但我遇到了错误。我试着改变
unsigned char state = 0;
至
unsigned char state;
state =0;
不走运。
错误是:
error: 'digital' does not name type
'blink' was not declared in this scope
'state' was not declared in this scope
码:
int SensorLED = 13; //define LED digital pin 13
int SensorINPUT = 3; // connect tilt sensor to interrupt 1 in
digital pin 3
unsigned char state = 0;
void setup() {
pinMode(SensorLED, OUTPUT); //configure LED as output mode
pinMode(SensorINPUT, INPUT); //configure tilt sensor as input mode
//when low voltage changes to high voltage, it triggers interrupt 1 and runs the blink function
attachInterrupt(1, blink, RISING);
}
void loop(){
if(state!=0){ // if state is not 0
state = 0; // assign state value 0
digitalWrite(SensorLED,HIGH); // turn on LED
delay(500); // delay for 500ms
}
else{
digitalWrite(SensorLED,LOW); // if not, turn off LED
}
}
void blink(){ // interrupt function blink()
state++; //once trigger the interrupt, the state keeps increment
}
发布于 2017-08-24 07:53:32
首先,
unsigned char state = 0;
和
unsigned char state;
state =0;
是完全一样的。
代码中digital pin 3
行的含义是什么。您已经定义了SensorINPUT = 3
,使其成为INPUT
将使pin D3
作为输入引脚。
因此,只要删除这一行,代码就会编译得很好。其余的错误似乎仅仅是由于这一行。
发布于 2017-08-24 07:56:04
我不是在评论功能,但错误可以这样修正:
const byte SensorLED = 13;
const byte SensorINPUT = 3;
volatile byte state = LOW;
void blink(void)
{
state = !state;
}
void setup()
{
pinMode(SensorLED, OUTPUT);
pinMode(SensorINPUT, INPUT);
attachInterrupt(1, blink, RISING);
}
void loop()
{
digitalWrite(SensorLED, state);
delay(500);
}
https://stackoverflow.com/questions/45853069
复制相似问题