【2024 DigiKey 创意大赛】二月柳絮大作战项目-07控制外设I/O的输出控制
[复制链接]
本帖最后由 Maker_kun 于 2024-11-3 14:45 编辑
查看原理图可以得到扩展IO引脚分布及注意事项:
EX_IO4、EX_IO5、EX_IO6、EX_IO7可以无条件使用
打开案例库:ESP32_IO_Expander
IIC引脚为IO47、IO48
修改代码如下:
#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);
}
让EX_IO4、EX_IO5、EX_IO6、EX_IO7不断切换开关状态
效果演示:
|