加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CS1237气泵参考代码.txt 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
慕炎 提交于 2022-01-10 06:14 . CS1237气泵参考代码
int ndrdy = A4;
int clck = A5;
int pwm = 3;
void setup() {
Serial.begin(115200);
pinMode(pwm, OUTPUT);
while (!Serial) {}
digitalWrite(ndrdy, LOW);
pinMode(ndrdy, INPUT);
digitalWrite(clck, LOW);
pinMode(clck, OUTPUT);
while (digitalRead(ndrdy)) {}
while (!digitalRead(ndrdy)) {}
}
long readADC()
{
if (digitalRead(ndrdy))
return -1;
long result = 0;
for (int i = 0; i < 24; i++)
{
digitalWrite(clck, HIGH);
delayMicroseconds(1);
int new_bit = digitalRead(ndrdy);
digitalWrite(clck, LOW);
delayMicroseconds(1);
result <<= 1;
result |= new_bit;
}
for (int i = 0; i < 3; i++)
{
digitalWrite(clck, HIGH);
delayMicroseconds(1);
digitalWrite(clck, LOW);
delayMicroseconds(1);
}
return result;
}
void loop() {
long adcValue = readADC();
Serial.print("ADC reading: ");
Serial.print(adcValue);
if (adcValue >= 3400000)
{
delay(500);
analogWrite(pwm,0);
Serial.println(" End of Run ");
delay(500);
}
else
{
if (is_run == true)
{
analogWrite(pwm,255);
delay(500);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化