【2024 DigiKey 创意大赛】二月柳絮大作战项目-07控制外设I/O的输出控制
本帖最后由 Maker_kun 于 2024-11-3 14:45 编辑<p> </p>
<p>查看原理图可以得到扩展IO引脚分布及注意事项:</p>
<p> </p>
<p></p>
<p> </p>
<p><strong>EX_IO4、EX_IO5、EX_IO6、EX_IO7可以无条件使用</strong></p>
<p> </p>
<p>打开案例库:ESP32_IO_Expander</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>IIC引脚为IO47、IO48</p>
<p>修改代码如下:</p>
<pre>
<code>#include <Arduino.h>
#include <ESP_IOExpander_Library.h>
#define EXAMPLE_CHIP_NAME TCA95xx_8bit
#define EXAMPLE_I2C_NUM (0)
#define EXAMPLE_I2C_SDA_PIN (47)
#define EXAMPLE_I2C_SCL_PIN (48)
#define _EXAMPLE_CHIP_CLASS(name, ...) ESP_IOExpander_##name(__VA_ARGS__)
#define EXAMPLE_CHIP_CLASS(name, ...) _EXAMPLE_CHIP_CLASS(name, ##__VA_ARGS__)
ESP_IOExpander *expander = NULL;
void setup()
{
expander = new EXAMPLE_CHIP_CLASS(EXAMPLE_CHIP_NAME,
(i2c_port_t)EXAMPLE_I2C_NUM, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000,
EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN);
expander->init();
expander->begin();
expander->pinMode(4, OUTPUT);
expander->pinMode(5, OUTPUT);
expander->multiPinMode(IO_EXPANDER_PIN_NUM_6 | IO_EXPANDER_PIN_NUM_7, OUTPUT);
expander->digitalWrite(4, LOW);
expander->digitalWrite(5, LOW);
expander->multiDigitalWrite(IO_EXPANDER_PIN_NUM_6 | IO_EXPANDER_PIN_NUM_7, LOW);
}
void loop()
{
expander->digitalWrite(4, HIGH);
expander->digitalWrite(5, HIGH);
expander->digitalWrite(6, HIGH);
expander->digitalWrite(7, HIGH);
delay(500);
expander->digitalWrite(4, LOW);
expander->digitalWrite(5, LOW);
expander->digitalWrite(6, LOW);
expander->digitalWrite(7, LOW);
delay(500);
}
</code></pre>
<p> </p>
<p>让EX_IO4、EX_IO5、EX_IO6、EX_IO7不断切换开关状态</p>
<p>效果演示:</p>
<div style="text-align: left;"></div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
页:
[1]