根据这段话来控制呼吸传感器信号的输出
Every 1ms collect one analog signal reading (ADC is 10-bit, giving values in the range 0 to
1023)
Integrate collected analog signal readings to reduce noise. Sum 25 readings.
If sum is less than 1500 (low reading), then try to increase the gain by multiplexing between
different feedback resistors using Arduino digital outputs 22, 24, 26 or 28.
If sum is more than 14800 (high reading), then try to reduce the gain by multiplexing between
different resistors using Arduino digital outputs 22, 24, 26 or 28.
Every 100ms send the reading over Bluetooth (write to Arduino UART output)
下面是我编的程序,大神们看看问题出现在哪里
[kenrobot_code]int val;//定义一个变量
int pin1=2;//增益选择开关通道接入的引脚
int pin2=3;
int pin3=4;
inputPin=A0;//模拟输入引脚
int sum=0;//定义求和变量
int sensorVal;//定义一个变量
void setup() {
Serial.begin(9600);//设定串口的通讯速率
pinMode(inputPin,INPUT);//定义模拟引脚为输入
for(int i=2;i<=4;i++){
pinMode(i,OUTPUT);//定义增益选择开关通道接入的引脚为输出
}
}
void loop() {
for(int i=0;i<=24;i++)
{
val=analogRead(A0);
delay(1);
sum+=val;//读取模拟端口的值25次并求和
}
sensorVal=sum;
if(sensorVal<1500){
digitalWrite(pin1,HIGH);//判断25次求和后的值小于1500时,给增益选择通道引脚2高电平,然后每隔100毫秒输出模拟端口的值
delay(100);
Serial.println(val);
}
if(sensorVal>14800){
digitalWrite(pin3,HIGH);
delay(100);
Serial.println(val);//判断25次求和后的值大于14800时,给增益选择通道引脚4高电平,然后每隔100毫秒输出模拟端口的值
}
else{
digitalWrite(pin2,HIGH);
delay(100);
Serial.println(val);//判断25次求和后的值大于1500小于14800时,给增益选择通道引脚3高电平,然后每隔100毫秒输出模拟端口的值
}
}[/kenrobot_code] |