我学校的一些学生正在研究测量振动(例如地震)的项目,并将两个传感器(压电式爆震和振动传感器)的结果打印到液晶屏蔽。他们可能从互联网上编译了一些代码。他们的原始代码是这样的:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int referansDegeri = 800;
int knockSensor = 0;
int val = 0;
int sensorLevel = map;
int statePin = LOW;
int THRESHOLD = 100;
const int analogPin = A0;
int vib_pin=7;
void setup()
{
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int sensorLevel = map(sensorReading, 0, 1023, 0, sensorCount);
pinMode(vib_pin,INPUT);
Serial.begin(9600);
}
void loop()
{
int sensorDegeri = analogRead(A0);
Serial.print(sensorDegeri); //Okuduğumuz değer ekrana yazdırılıyor
if (sensorDegeri >= referansDegeri){
Serial.println("siddetli sarsinti");
}
else{
Serial.println("dusuk sarsinti");
}
delay(1);
}
val = analogRead(knockSensor);
if (val >= THRESHOLD) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
Serial.println("Knock!");
delay(100);
int val;
val=digitalRead(vib_pin);
if(val==1)
{
digitalWrite(led_pin,HIGH);
delay(1000);
digitalWrite(led_pin,LOW);
delay(1000);
}
else
digitalWrite(led_pin,LOW);
}
此代码给出了此错误(退出状态):
&#39; sensorCount&#39;未在此范围内声明
知道学生有一个爆震传感器,我将sensorCount更改为1,同时映射它似乎
int sensorLevel = map(sensorReading, 0, 1023, 0, 1);
然后它开始提供此错误(退出状态):
然而,我做了一些搜索,找不到具体的结果,所以无法解决问题。但我相信重要的是要提到学生之前使用LED条形图和LCD屏幕,但他们现在已经删除了它。&#39; VAL&#39;没有命名类型