Arduino
环境和项目
GPIO
pinMode(pin, mode)
INPUT
OUTPUT
INPUT_PULLUP
digitalWrite(pin,value)
digitalRead(pin)
analogRead(pin)
模拟输入analogSetWidth(bit)
模拟输入分辨率- pwm输出
ledcSetup(channel,freq,bit_num)
设置ledcAttachPin(pin,channel)
映射ledcDetachPin(pin)
取消映射ledcWrite(channel,duty)
占空比analogWrite()
dacWrite(pin,value)
硬件dac
中断和定时器
- 外部中断
attachInterrupt(interrupt,function,mode)
设置detachInterrupt(interrupt)
关闭interrupts()
nolnterrupts()
总开关
- 定时器
- 配置略
Timer::set(500, function)
中断设置Timer::start()
开始计时Ticker.h
Ticker ticker
ticker.attach(1, func, arg)
通信
- UART
Serial
.begin(speed, config)
.end()
.print()
printf() println().write()
.available()
- read
.read()
.readBytes()
.readString()
.readStringUntil()
.find()
.findUntil()
.parseFloat()
.parseInt()
.setTimeout()
- I2C
Wire
.begin([add])
从机要写地址.requestFrom(address, quantity)
.beginTransmission(address)
开始传输.endTransmission()
.write(data)
.available()
.read()
.onReceive(handler)
.onRequest(handler)
- SPI
SPI
.begin()
.setClockDivider(div)
分频.transfer(val)
传送.beginTransaction(SPISettings(speedMaximum,dataOrder,dataMode))
.attachInterrupt(handler)
回调
网络
WIFI
WIFI.mode(WIFI_MODE_AP/STA)
.getMode()
.enableSTA/AP(true)
.setSleep(true)
- AP
.softAP()
.softAPConfig()
.disconnect()
- 查看修改各项配置略
- STA
.begin(ssid passwd)
.isConnected()
连上了没.localIP()
.status()
- 查看修改各项配置略
.disconnect()
.setAutoReCoennect()
.scanNetworks()
scanComplete()
- 智能配网
.beginSmartConfig()
.smartConfigDone()
蓝牙
BluetoothSerial.h
.begin("ESP32BLE")
.available()
.read()
.write()
BLEDevice.h
略
双核
- 不建议在连接wifi蓝牙时使用
xTaskCreatePinnedToCore(task,"task",1024,NULL,1,NULL,0/1)
核心0/1xPortGetCoreID()
查看任务在哪个核心上