MianQi 发表于 2021-9-2 09:40

[FS-IR02 + D1CS-D54] - 5:跟MCU联动(D1CS-D54)

本帖最后由 MianQi 于 2021-9-2 09:39 编辑

<p>MCU用的是Arduino UNO。</p>

<p>&nbsp;</p>

<p>实物照:</p>

<p></p>

<p></p>

<p>&nbsp;</p>

<p>演示视频:</p>

<p><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1UL411476D&amp;page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe></p>

<p>&nbsp;</p>

<p>示例代码:</p>

<pre>
<code class="language-cpp">/*
* code for tesing D1CS-D54 capacitive(non-contacting) liquid level sensor
* Author:MianQi
* Date:Sep.1, 2021
* Version:0.0
*/

/*
* Wiring:
* Sensor data ---&gt; Arduino UNO D2 &amp; 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);
}</code></pre>

<p>&nbsp;</p>

soso 发表于 2021-9-2 10:16

<p>厉害了。看着真好玩。</p>
页: [1]
查看完整版本: [FS-IR02 + D1CS-D54] - 5:跟MCU联动(D1CS-D54)