[FS-IR02 + D1CS-D54] - 5:跟MCU联动(D1CS-D54)
[复制链接]
本帖最后由 MianQi 于 2021-9-2 09:39 编辑
MCU用的是Arduino UNO。
实物照:
演示视频:
示例代码:
/*
* code for tesing D1CS-D54 capacitive(non-contacting) liquid level sensor
* Author:MianQi
* Date:Sep.1, 2021
* Version:0.0
*/
/*
* Wiring:
* Sensor data ---> Arduino UNO D2 & D3
*/
#define LED_0 7
#define LED_1 8
#define interruptPin_0 2
#define interruptPin_1 3
void setup() {
// put your setup code here, to run once:
pinMode(LED_0, OUTPUT);
pinMode(LED_1, OUTPUT);
pinMode(interruptPin_0, INPUT_PULLUP);
pinMode(interruptPin_1, INPUT_PULLUP);
//"LOW" for NPN transisitor, "HIGH" for PNP transistor
digitalWrite(LED_0, HIGH);
digitalWrite(LED_1, HIGH);
attachInterrupt(digitalPinToInterrupt(interruptPin_0), blinkLed0, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin_1), blinkLed1, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
}
void blinkLed0(void){
digitalWrite(LED_0, LOW);
digitalWrite(LED_1, HIGH);
}
void blinkLed1(void){
digitalWrite(LED_0, HIGH);
digitalWrite(LED_1, LOW);
}
|