add API Arduino

This commit is contained in:
lin-zi-jun
2019-08-15 19:29:40 +08:00
parent dfa676929e
commit c371a80175
12 changed files with 2495 additions and 21 deletions
+250
View File
@@ -0,0 +1,250 @@
## run()
**Syntax:**
<mark>run()</mark>
**Description:**
this function must be called inside loop()
## setInterval()
**Syntax:**
<mark>int setInterval(long d, timer_callback f)</mark>
**Description:**
call function f every d milliseconds
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| d | long | milliseconds |
| f | function | timer_callback function |
**Example:**
```arduino
#include <M5Stack.h>
#include "utility/M5Timer.h"
M5Timer M5timer;
void repeatMe(){
M5.Lcd.setCursor(0,0);
M5.Lcd.clear();
M5.Lcd.print("Uptime(s): ");
M5.Lcd.println(millis()/1000);
}
void setup() {
M5.begin();
M5timer.setInterval(1000, repeatMe);
}
void loop() {
M5timer.run();
}
```
## setTimeout()
**Syntax:**
<mark>int setTimeout(long d, timer_callback f)</mark>
**Description:**
call function f once after d milliseconds
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| d | long | milliseconds |
| f | function | timer_callback function |
**Example:**
```arduino
#include <M5Stack.h>
#include "utility/M5Timer.h"
M5Timer M5timer;
void Timeout(){
M5.Lcd.setCursor(0,0);
M5.Lcd.clear();
M5.Lcd.print("Timeout(s): ");
M5.Lcd.println(millis()/1000);
}
void setup() {
M5.begin();
M5timer.setTimeout(5000, Timeout);
}
void loop() {
M5timer.run();
}
```
## setTimer()
**Syntax:**
<mark>int setTimer(long d, timer_callback f, int n);</mark>
**Description:**
call function f every d milliseconds for n times
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| d | long | milliseconds |
| f | function | timer_callback function |
| n | int | Number of executions |
**Example:**
```arduino
#include <M5Stack.h>
#include "utility/M5Timer.h"
M5Timer M5timer;
void Timer(){
M5.Lcd.print("Timeout(s): ");
M5.Lcd.println(millis()/1000);
}
void setup() {
M5.begin();
M5timer.setTimer(2000, Timer, 3);
}
void loop() {
M5timer.run();
}
```
## Enable()
**Syntax:**
<mark>void Enable(int numTimer)</mark>
**Description:**
enables the specified timer
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| numTimer | int | timer id |
**Example:**
```arduino
#include <M5Stack.h>
#include "utility/M5Timer.h"
M5Timer M5timer;
int timerId = 1;
void setup() {
M5.begin();
M5timer.enable(timerId);
}
void loop() {
M5timer.run();
if (M5timer.isEnabled(timerId)){
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("Timer is enable ");
M5.Lcd.println(millis()/1000);
}
}
```
## isEnabled()
**Syntax:**
<mark>boolean isEnabled(int numTimer)</mark>
**Description:**
returns true if the specified timer is enabled
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| numTimer | int | timer id |
**Example:**
```arduino
#include <M5Stack.h>
#include "utility/M5Timer.h"
M5Timer M5timer;
int timerId = 1;
void setup() {
M5.begin();
M5timer.enable(timerId);
}
void loop() {
M5timer.run();
if (M5timer.isEnabled(timerId)){
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("Timer is enable ");
M5.Lcd.println(millis()/1000);
}
}
```
## Disable()
**Syntax:**
<mark>void Disable(int numTimer)</mark>
**Description:**
disables the specified timer
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| numTimer | int | timer id |
**Example:**
```arduino
#include <M5Stack.h>
#include "utility/M5Timer.h"
M5Timer M5timer;
int timerId = 1;
void setup() {
M5.begin();
M5timer.enable(timerId);
}
void loop() {
M5timer.run();
if (M5timer.isEnabled(timerId)){
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("Timer is enable ");
M5.Lcd.println(millis()/1000);
}
while (millis() > 5000){
M5timer.disable(timerId);
}
}
```
+118
View File
@@ -21,6 +21,124 @@ void setup() {
void loop() {}
```
## GetWarningLeve()
**Syntax:**
<mark>uint8_t GetWarningLeve(void);</mark>
**Description: get current warning level.**
**Example:**
```arduino
#include <M5StickC.h>
int level;
void setup() {
M5.begin();
}
void loop() {
level = M5.Axp.GetWarningLeve();
M5.Lcd.setCursor(0, 0);
M5.Lcd.print(level);
}
```
## LightSleep()
**Syntax:**
<mark>void LightSleep(uint64_t time_in_us = 0)</mark>
**Description: control ESP32 into LightSleep Mode ,Press power swith to wakeup.**
| parameter | description |
| --- | --- |
| time_in_us| sleep time in us|
**Example:**
```arduino
#include <M5StickC.h>
int count = 0;
void setup() {
M5.begin();
M5.Lcd.fillScreen(WHITE);
pinMode(M5_BUTTON_HOME,INPUT_PULLUP);
}
void loop() {
if(digitalRead(M5_BUTTON_HOME) == LOW){
while(digitalRead(M5_BUTTON_HOME) == LOW);
M5.Axp.LightSleep(SLEEP_SEC(5)); //SLEEP_SEC(us) (((uint64_t)us) * 1000000L)
}
count++;
M5.Lcd.setCursor(60, 30);
M5.Lcd.setTextColor(BLACK, WHITE);
M5.Lcd.print(count);
}
```
## SetSleep()
**Syntax:**
<mark>void SetSleep(void);</mark>
**Description: control external device into Sleep Mode,Press power switch to wakeup.**
**Example:**
```arduino
#include <M5StickC.h>
void setup() {
M5.begin();
M5.Lcd.fillScreen(WHITE);
pinMode(M5_BUTTON_HOME,INPUT_PULLUP);
M5.Lcd.setCursor(60, 30);
M5.Lcd.print("SLEEP");
}
void loop() {
if(digitalRead(M5_BUTTON_HOME) == LOW){
while(digitalRead(M5_BUTTON_HOME) == LOW);
M5.Axp.SetSleep();
}
}
```
## DeepSleep()
**Syntax:**
<mark>void DeepSleep(uint64_t time_in_us = 0)</mark>
**Description: control external device into DeepSleep Mode,When timeout device auto wakeup.**
**Example:**
```arduino
#include <M5StickC.h>
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(WHITE);
M5.Lcd.setTextColor(BLACK, WHITE);
pinMode(M5_BUTTON_HOME,INPUT_PULLUP);
M5.Lcd.setCursor(60, 30);
M5.Lcd.print("SLEEP");
}
void loop() {
if(digitalRead(M5_BUTTON_HOME) == LOW){
while(digitalRead(M5_BUTTON_HOME) == LOW);
M5.Axp.DeepSleep(SLEEP_SEC(5));
}
}
```
## ScreenBreath()
**Syntax:**
+128 -3
View File
@@ -4,7 +4,7 @@
**Syntax:**
<mark>uint8_t read();</mark>
<mark>uint8_t read()</mark>
**Description:**
@@ -30,7 +30,7 @@ void loop() {
**Syntax:**
<mark>uint8_t isPressed();</mark>
<mark>uint8_t isPressed()</mark>
**Description:**
@@ -60,7 +60,7 @@ void loop() {
**Syntax:**
<mark>uint8_t wasPressed();</mark>
<mark>uint8_t wasPressed()</mark>
**Description:**
@@ -86,6 +86,40 @@ void loop() {
}
```
## releasedFor()
**Syntax:**
<mark>uint8_t releasedFor(uint32_t ms)</mark>
**Description:**
releasedFor(ms) check to see if the button is pressed (or released), and has been in that state for the specified time in milliseconds. Returns false (0) or true (1) accordingly.
**Example:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
}
void loop() {
M5.update();
M5.Lcd.clear();
M5.Lcd.setCursor(0, 0);
if (M5.BtnA.wasPressed()) {
M5.Lcd.printf("Button A was pressed.");
delay(1000);
}
}
```
## pressedFor()
**Syntax:**
@@ -119,3 +153,94 @@ void loop() {
}
}
```
## lastChange()
**Syntax:**
<mark>uint32_t lastChange(void);</mark>
**Description:**
Returns the last state time point .
**Example:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
}
void loop() {
M5.update();
int current_time = M5.BtnB.lastChange();
M5.Lcd.setCursor(0, 0);
M5.Lcd.printf("The last change at No. %d ms",current_time);
}
```
## wasReleasefor()
**Syntax:**
<mark>uint8_t wasReleasefor(uint32_t ms);</mark>
**Description:**
releasedFor(ms) check to see if the button is released, and has been in that state for the specifiedtime in milliseconds. Returns false (0) or true (1) accordingly .
**Example:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("press Button A to display message");
delay(3000);
}
void loop() {
M5.update();
if (M5.BtnA.isPressed()){
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("release Button A, 3 seconds will clear screen");
}
if (M5.BtnA.releasedFor(3000)) {
M5.Lcd.clear(BLACK);
}
}
```
## wasReleased()
**Syntax:**
<mark>uint8_t wasReleased(void)</mark>
**Description:**
This function returns 1 only once each time the button is pressed. 1: pressed, 0: released.
**Example:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Lcd.print("Press Button A and release, you will see the message");
}
void loop() {
M5.update();
if (M5.BtnA.wasReleased()){
M5.Lcd.clear();
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("Button A was Released");
}
}
```
+66
View File
@@ -0,0 +1,66 @@
## EEPROM.begin()
**Syntax:**
<mark>EEPROM.begin(size)</mark>
**Description:**
Load <EEPROM.h> before use
Open EEPROM,Size is the maximum address + 1 of the data bytes to be read and written, ranging from 1 to 4096.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| size | int | EEPROM size |
## EEPROM.write()
**Syntax:**
<mark>EEPROM.write(addr, data)</mark>
**Description:**
Load <EEPROM.h> before use
Write data to storage space.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| addr | int | Address of storage space |
| data | int | Actual Write Data |
## EEPROM.commit()
**Syntax:**
<mark>EEPROM.commit()</mark>
**Description:**
Load <EEPROM.h> before use
This function needs to be called every time an address is written.
**Function argument**
None
## EEPROM.read()
**Syntax:**
<mark>EEPROM.read(addr)</mark>
**Description:**
Load <EEPROM.h> before use
Reading data from storage space.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| addr | int | Address of storage space |
+316 -9
View File
@@ -48,7 +48,7 @@
**Syntax:**
<mark>int digitalRead(uint8_t pin);</mark>
<mark>int digitalRead(uint8_t pin)</mark>
**Description:**
@@ -81,7 +81,7 @@ pin21_data = digitalRead(21);
**Syntax:**
<mark>void digitalWrite(uint8_t pin, uint8_t val);</mark>
<mark>void digitalWrite(uint8_t pin, uint8_t val)</mark>
**Description:**
@@ -115,7 +115,7 @@ digitalWrite(2,1);
**Syntax:**
<mark>void pinMode(uint8_t pin, uint8_t mode);</mark>
<mark>void pinMode(uint8_t pin, uint8_t mode)</mark>
**Description:**
@@ -149,7 +149,7 @@ pinMode(2,INPUT);
## analogRead()
**Syntax:**
<mark>uint16_t analogRead(uint8_t pin);</mark>
<mark>uint16_t analogRead(uint8_t pin)</mark>
**Description:**
@@ -180,7 +180,7 @@ ret=analogRead(35);
**Syntax:**
<mark>void dacWrite(uint8_t pin, uint8_t value);</mark>
<mark>void dacWrite(uint8_t pin, uint8_t value)</mark>
**Description:**
@@ -211,7 +211,7 @@ dacWrite(25,0x40);
**Syntax:**
<mark>double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits);</mark>
<mark>double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits)</mark>
**Description:**
@@ -241,7 +241,7 @@ It is good to recognize that it is a number to memorize the setting.
**Syntax:**
<mark>void ledcAttachPin(uint8_t pin, uint8_t chan);</mark>
<mark>void ledcAttachPin(uint8_t pin, uint8_t chan)</mark>
**Description:**
@@ -263,7 +263,7 @@ None.
**Syntax:**
<mark>void ledcWrite(uint8_t chan, uint32_t duty);</mark>
<mark>void ledcWrite(uint8_t chan, uint32_t duty)</mark>
**Description:**
@@ -291,7 +291,7 @@ When specifying with 8 bits, specifying 0xFF results in 100% output.
**Syntax:**
<mark>void ledcDetachPin(uint8_t pin);</mark>
<mark>void ledcDetachPin(uint8_t pin)</mark>
**Description:**
@@ -307,3 +307,310 @@ Release the assigned port and stop the output.
**Function return value:**
None.
## analogSetCycles()
**Syntax:**
<mark>void analogSetCycles(uint8_t cycles)</mark>
**Description:**
Set the period of a single sampling, value 1-255, default 8.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| cycles | uint8_t | sampling period |
**Function return value:**
None
## analogSetWidth()
**Syntax:**
<mark>void analogSetWidth(uint8_t bits)</mark>
**Description:**
Set the ADC sampling resolution to 9-12, default to 12.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| bits | uint8_t | sampling resolution |
**Function return value:**
None
## analogReadResolution()
**Syntax:**
<mark>void analogReadResolution(uint8_t bits)</mark>
**Description:**
Set the reading resolution of analog data, value 1 to 16, default is 12. If it is between 9 and 12, it will be equal to the set hardware resolution, otherwise the value will be moved.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| bits | uint8_t | sampling resolution |
**Function return value:**
None
## analogSetSamples()
**Syntax:**
<mark>void analogSetSamples(uint8_t samples)</mark>
**Description:**
Set the actual sampling times of single sampling, take the value of 1 ~ 255, default is 1;
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| samples | uint8_t | sampling times |
**Function return value:**
None
## analogSetAttenuation()
**Syntax:**
<mark>void analogSetAttenuation(adc_attenuation_t attenuation)</mark>
**Description:**
Set the global input attenuation of ADC to ADC_0db, ADC_2_5db, ADC_6db, ADC_11db, default to 11 DB
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| attenuation | adc_attenuation_t | attenuation |
**Function return value:**
None
## analogSetPinAttenuation()
**Syntax:**
<mark>void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation)</mark>
**Description:**
Setting input attenuation for a single IO port
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | uint8_t | specified pin |
| attenuation | adc_attenuation_t | attenuation |
**Function return value:**
None
## hallRead()
**Syntax:**
<mark>int hallRead(void));</mark>
**Description:**
Read Hall Sensor.
**Function argument**
None
**Function return value:**
None.
## attachInterrupt()
**Syntax:**
<mark>void attachInterrupt(pin, ISR(callback function), interrupt type/mode)</mark>
**Description:**
set pin interrupt.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | uint8_t | pin No. |
| ISR | callcack function | which function you want excute |
| interrupt | mode | CHANGE/RISING/FALLING |
**Function return value:**
None.
## detachInterrupt()
**Syntax:**
<mark>void detachInterrupt(pin)</mark>
**Description:**
Prohibit specified pin interruptio.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | uint8_t | pin No. |
**Function return value:**
None.
## ledcReadFreq()
**Syntax:**
<mark>double ledcReadFreq(uint8_t channel)</mark>
**Description:**
Returns the current frequency of the specified channel.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| channel | uint8_t | specified channel |
**Function return value:**
current frequency
## ledcRead()
**Syntax:**
<mark>uint32_t ledcRead(uint8_t channel)</mark>
**Description:**
Returns the value of the specified channel duty cycle.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| channel | uint8_t | specified channel |
**Function return value:**
duty cycle
## adcAttachPin()
**Syntax:**
<mark>bool adcAttachPin(uint8_t pin)</mark>
**Description:**
This is Non-blocking mode.Connect pins to ADC (and remove any other analog modes that may be opened).
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | uint8_t | specified pin |
**Function return value:**
Return 1 if boot succeeds
## adcStart()
**Syntax:**
<mark>bool adcStart(uint8_t pin)</mark>
**Description:**
This is Non-blocking Start ADC Conversion on Connected Pins.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | uint8_t | specified pin |
**Function return value:**
Return 1 if boot succeeds
## adcBusy()
**Syntax:**
<mark>bool adcBusy(uint8_t pin)</mark>
**Description:**
This is Non-blocking mode Check whether the ADC conversion is in progress.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | uint8_t | specified pin |
**Function return value:**
Conversion returning 1
## adcEnd()
**Syntax:**
<mark>uint16_t adcEnd(uint8_t pin)</mark>
**Description:**
This is Non-blocking mode Get the result of the transformation (wait if it's not finished).
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| pin | uint8_t | specified pin |
**Function return value:**
Returns the conversion result
+776 -8
View File
File diff suppressed because it is too large Load Diff
+41 -1
View File
@@ -260,4 +260,44 @@ void loop() {
}
delay(500);
}
```
```
## readTempData()
**Syntax:**
<mark>int16_t readTempData(void);</mark>
**Description:**
This function reads the temperature.
**Example:**
```arduino
#include <M5Stack.h>
#include "utility/MPU9250.h"
MPU9250 IMU; // new a MPU9250 object
void setup()
{
M5.begin();
Wire.begin();
IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias);
IMU.initMPU9250();
IMU.initAK8963(IMU.magCalibration);
}
void loop()
{
IMU.tempCount = IMU.readTempData();
IMU.temperature = ((float) IMU.tempCount) / 333.87 + 21.0;
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("MPU9250 Temperature is ");
M5.Lcd.print(IMU.temperature, 1);
delay(500);
}
```
+139
View File
@@ -0,0 +1,139 @@
## SetTime()
**Syntax:**
<mark>void SetTime(RTC_TimeTypeDef* RTC_TimeStruct)</mark>
**Description:**
Set time with the value of the structure member variable
**Example:**
```arduino
#include <M5StickC.h>
RTC_TimeTypeDef TimeStruct;
void setup() {
M5.begin();
TimeStruct.Hours = 18;
TimeStruct.Minutes = 56;
TimeStruct.Seconds = 10;
M5.Rtc.SetTime(&TimeStruct);
}
void loop(){};
```
## GetTime()
**Syntax:**
<mark>void GetTime(RTC_TimeTypeDef* RTC_TimeStruct)</mark>
**Description:**
Get time with the value of the structure member variable
**Example:**
```arduino
#include <M5StickC.h>
RTC_TimeTypeDef TimeStruct;
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(40, 0, 2);
M5.Lcd.println("RTC TEST");
TimeStruct.Hours = 18;
TimeStruct.Minutes = 56;
TimeStruct.Seconds = 10;
M5.Rtc.SetTime(&TimeStruct);
}
void loop() {
M5.Rtc.GetTime(&TimeStruct);
M5.Lcd.setCursor(0, 15);
M5.Lcd.printf("Time: %02d : %02d : %02d\n",TimeStruct.Hours, TimeStruct.Minutes, TimeStruct.Seconds);
delay(500);
}
```
## SetData()
**Syntax:**
<mark>void SetData(RTC_TimeTypeDef* RTC_DateStruct)</mark>
**Description:**
Set date with the value of the structure member variable
**Example:**
```arduino
#include <M5StickC.h>
RTC_TimeTypeDef TimeStruct;
RTC_DateTypeDef DateStruct;
void setup() {
M5.begin();
DateStruct.WeekDay = 3;
DateStruct.Month = 3;
DateStruct.Date = 22;
DateStruct.Year = 2019;
M5.Rtc.SetData(&DateStruct);
}
void loop(){};
```
## GetData()
**Syntax:**
<mark>void GetData(RTC_TimeTypeDef* RTC_DateStruct)</mark>
**Description:**
Get date with the value of the structure member variable
**Example:**
```arduino
#include <M5StickC.h>
RTC_DateTypeDef DateStruct;
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(40, 0, 2);
M5.Lcd.println("RTC TEST");
DateStruct.WeekDay = 3;
DateStruct.Month = 3;
DateStruct.Date = 22;
DateStruct.Year = 2019;
M5.Rtc.SetData(&DateStruct);
}
void loop() {
M5.Rtc.GetData(&DateStruct);
M5.Lcd.setCursor(0, 15);
M5.Lcd.printf("Data: %04d-%02d-%02d\n",DateStruct.Year, DateStruct.Month,DateStruct.Date);
M5.Lcd.printf("Week: %d\n",DateStruct.WeekDay);
delay(500);
}
+28
View File
@@ -83,4 +83,32 @@ void loop() {
((float)accZ) * M5.IMU.aRes);
delay(500);
}
```
## getTempData()
**Syntax:**
<mark>void getTempData(float* t);</mark>
**Description: It get SH200Q tempurature data.**
**Example:**
```arduino
#include <M5StickC.h>
float temp = 0;
void setup() {
M5.begin();
M5.IMU.Init();
}
void loop() {
M5.IMU.getTempData(&temp);
M5.Lcd.setCursor(0, 0);
M5.Lcd.printf("Temperature : %.2f C", temp);
delay(1000);
}
```
+20
View File
@@ -85,3 +85,23 @@ void setup() {
M5.Speaker.setBeep(900, 1000);
}
```
## mute()
**Description:**
Mute the sound .
**Syntax:**
<mark>void mute(void);</mark>
**Example of use:**
```arduino
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Speaker.mute();
}
```
+134
View File
@@ -0,0 +1,134 @@
## once()
**Syntax:**
<mark>void once(float seconds, callback_t callback)</mark>
**Description:**
Load <Ticker.h> before use
Execute a command in seconds, which is executed only once.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| seconds | float | Set time |
| callback | callback_t | Custom callback function |
## once_ms()
**Syntax:**
<mark>void once_ms(uint32_t milliseconds, callback_t callback)</mark>
**Description:**
Load <Ticker.h> before use
Execute a command in milliseconds, which is executed only once.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| milliseconds | float | Set time |
| callback | callback_t | Custom callback function |
## attach()
**Syntax:**
<mark>void attach(float seconds, void (*callback)(TArg), TArg arg)</mark>
**Description:**
Load <Ticker.h> before use
Execute commands with parameters after every seconds.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| seconds | float | Set time |
| *callback | callback_t | Custom callback function |
| TArg | arg | function arguments |
## attach_ms()
**Syntax:**
<mark>void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)</mark>
**Description:**
Load <Ticker.h> before use
Execute commands with parameters after every milliseconds.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| milliseconds | float | Set time |
| *callback | callback_t | Custom callback function |
| TArg | arg | function arguments |
## attach()
**Syntax:**
<mark>void attach(float seconds, callback_t callback)</mark>
**Description:**
Load <Ticker.h> before use
Execute the command after every second with no parameters.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| seconds | float | Set time |
| callback | callback_t | Custom callback function |
## attach_ms()
**Syntax:**
<mark>void attach_ms(uint32_t milliseconds, callback_t callback)</mark>
**Description:**
Load <Ticker.h> before use
Execute the command after every milliseconds with no parameters.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| seconds | float | Set time |
| callback | callback_t | Custom callback function |
## Usage {docsify-ignore}
```arduino
#include <M5Stack.h>
#include <Ticker.h>
Ticker tickerSetHigh;
Ticker tickerSetLow;
void display(int number) {
M5.Lcd.setCursor(0, 0);
M5.Lcd.print(number);
}
void setup() {
M5.begin();
tickerSetLow.attach_ms(1000, display, 0);
tickerSetHigh.attach_ms(2000, display, 1);
}
void loop() {
}
```
+479
View File
@@ -0,0 +1,479 @@
## WiFi.softAP()
**Syntax:**
<mark>bool WiFi.softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection)</mark>
**Description:**
Load <WiFi.h> before use
Use this method to open AP mode and return true after successful opening
**Function argument**
| Argument | Description | Type |
| --- | --- | -- |
| ssid |The name of an AP network 0-32 bytes | const char* |
| passphrase | password NULL or 8-63 bytes| const char* |
| ssid_hidden | Whether to hide SSID 1:hidden 0:not| int |
| max_conncetion | Maximum Accessibility Number 1-4 | int |
## WiFi.softAPConfig()
**Syntax:**
<mark>bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet)</mark>
**Description:**
Load <WiFi.h> before use
set AP IP address
**Function argument**
| Argument | Description | Type |
| --- | --- | -- |
| local_ip | local_ip defult 192.168.4.1 | IPAddress |
| gateway | gateway defult 192.168.4.1 | IPAddress |
| subnet | subnet mask defult 255.255.255.0 | IPAddress |
## WiFi.softAPdisconnect()
**Syntax:**
<mark>bool softAPdisconnect(bool wifioff = false)</mark>
**Description:**
Load <WiFi.h> before use
Turn off the current AP and restore the network settings if wifioff is true
**Function argument**
| Argument | Description | Type |
| --- | --- | -- |
| wifioff | Restore settings | bool |
## WiFi.softAPgetStationNum()
**Syntax:**
<mark>uint8_t softAPgetStationNum()</mark>
**Description:**
Load <WiFi.h> before use
Returns the number of clients connected to AP
**Function argument**
None
## WiFi.softAPIP()
**Syntax:**
<mark>IPAddress softAPIP()</mark>
**Description:**
Load <WiFi.h> before use
Returns current IP of AP
**Function argument**
None
## WiFi.softAPsetHostname()
**Syntax:**
<mark>bool softAPsetHostname(const char * hostname)</mark>
**Description:**
Load <WiFi.h> before use
Set Hostname if success return true
**Function argument**
| Argument | Description | Type |
| --- | --- | -- |
| hostname | set Hostname | const char* |
## WiFi.softAPgetHostname()
**Syntax:**
<mark>const char * softAPgetHostname()</mark>
**Description:**
Load <WiFi.h> before use
Get Hostname if success return true
**Function argument**
None
## WiFi.softAPmacAddress()
**Syntax:**
<mark>String softAPmacAddress(void)</mark>
**Description:**
Load <WiFi.h> before use
return MAC address
**Function argument**
None
## WiFi.begin()
**Syntax:**
<mark>wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true)</mark>
**Description:**
Load <WiFi.h> before use
This method is used to access the network .If connect equals true, it will connect to ssid's WiFi hotspot,If connect equals false, WiFi hotspots that are not connected to SSID will be created to save the above parameters.
**Function argument**
| Argument | Description | Type |
| --- | --- | -- |
| ssid |The name of an AP network 0-32 bytes | const char* |
| passphrase | password NULL or 8-63 bytes | const char* |
| channel | channel number | int32_t |
| bssid | MAC address of WiFi hotspot, optional parameters | const uint8_t* |
| connect | Establish a connection | bool |
## WiFi.config()
**Syntax:**
<mark>bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000)</mark>
**Description:**
Load <WiFi.h> before use
set network addresses.
**Function argument**
| Argument | Description | Type |
| --- | --- | -- |
| local_ip | local_ip defult 192.168.4.1 | IPAddress |
| gateway | gateway defult 192.168.4.1 | IPAddress |
| subnet | subnet mask defult 255.255.255.0 | IPAddress |
| dns1 | DNS address | IPAddress |
| dns2 | DNS address | IPAddress |
## WiFi.disconnect()
**Syntax:**
<mark>bool disconnect(bool wifioff = false, bool eraseap = false)</mark>
**Description:**
Load <WiFi.h> before use
If wifioff is true, the network settings will be restored. If eraseap is true, the network parameters saved in flash will be cleared.
**Function argument**
| Argument | Description | Type |
| --- | --- | -- |
| wifioff | Restore settings | bool |
| eraseap | erase ap from flash | bool |
## WiFi.isConnected()
**Syntax:**
<mark>bool isConnected()</mark>
**Description:**
Load <WiFi.h> before use
Returns whether the network has been accessed or not.
**Function argument**
None
## WiFi.setAutoReconnect()
**Syntax:**
<mark>bool setAutoReconnect(bool autoReconnect)</mark>
**Description:**
Load <WiFi.h> before use
RSetting up automatic reconnection after disconnection.
**Function argument**
None
## WiFi.setAutoReconnect()
**Syntax:**
<mark>bool getAutoReconnect()</mark>
**Description:**
Load <WiFi.h> before use
Setting up automatic reconnection after disconnection.
**Function argument**
None
## WiFi.localIP()
**Syntax:**
<mark>IPAddress localIP()</mark>
**Description:**
Load <WiFi.h> before use
Return local IP address.
**Function argument**
None
## WiFi.subnetMask()
**Syntax:**
<mark>IPAddress subnetMask()</mark>
**Description:**
Load <WiFi.h> before use
Return subnet mask.
**Function argument**
None
## WiFi.gatewayIP()
**Syntax:**
<mark>IPAddress gatewayIP()</mark>
**Description:**
Load <WiFi.h> before use
Return gateway IP address.
**Function argument**
None
## WiFi.dnsIP()
**Syntax:**
<mark>IPAddress dnsIP(uint8_t dns_no = 0)</mark>
**Description:**
Load <WiFi.h> before use
Return DNS address.
**Function argument**
None
## WiFi.macAddress()
**Syntax:**
<mark>String macAddress()</mark>
**Description:**
Load <WiFi.h> before use
Return MAC address.
**Function argument**
None
## WiFi.getHostname()
**Syntax:**
<mark>const char * getHostname()</mark>
**Description:**
Load <WiFi.h> before use
Return Hostname.
**Function argument**
None
## WiFi.status()
**Syntax:**
<mark>wl_status_t status()</mark>
**Description:**
Load <WiFi.h> before use
Return WIFI status.
**Function return value**
| value |Description |
| --- | --- |
| 255 | WL_NO_SHIELD |
| 0 | WL_IDLE_STATUS |
| 1 | WL_NO_SSID_AVAIL |
| 2 | WL_SCAN_COMPLETED |
| 3 | WL_CONNECTED |
| 4 | WL_CONNECT_FAILED |
| 5 | WL_CONNECTION_LOST |
| 6 | WL_DISCONNECTED |
## WiFi.scanNetworks()
**Syntax:**
<mark>int16_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300)</mark>
**Description:**
Load <WiFi.h> before use
scan wifi networks.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| async | false | Asynchronous scanning,the value is true, will not block |
| show_hidden | false | Whether to scan non-broadcast networks |
| passive | bool | boost scan |
| max_ms_per_chan | uint32_t | Scanning time per channel |
## WiFi.scanComplete()
**Syntax:**
<mark>int16_t scanComplete()</mark>
**Description:**
Load <WiFi.h> before use
Asynchronous mode is used to obtain the number of scanned networks. If the return value is - 1, it means that the scan is still in progress. If the return value is - 2, it means that the scan has not been done or failed.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| async | false | Asynchronous scanning,the value is true, will not block |
| show_hidden | false | Whether to scan non-broadcast networks |
| passive | bool | boost scan |
| max_ms_per_chan | uint32_t | Scanning time per channel |
## WiFi.scanDelete()
**Syntax:**
<mark>void scanDelete()</mark>
**Description:**
Load <WiFi.h> before use
Delete scan results in memory.
**Function argument**
None
## WiFi.SSID()
**Syntax:**
<mark>String SSID(uint8_t networkItem)</mark>
**Description:**
Load <WiFi.h> before use
Returns the scanned network name.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| networkItem | uint8_t | SSID item |
## WiFi.encryptionType()
**Syntax:**
<mark>wifi_auth_mode_t encryptionType(uint8_t networkItem)</mark>
**Description:**
Load <WiFi.h> before use
Returns the type of network encryption scanned.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| networkItem | uint8_t | SSID item |
## WiFi.RSSI()
**Syntax:**
<mark>int32_t RSSI(uint8_t networkItem)</mark>
**Description:**
Load <WiFi.h> before use
Return the scanned network signal strength.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| networkItem | uint8_t | RSSI item |
## WiFi.channel()
**Syntax:**
<mark>int32_t channel(uint8_t networkItem)</mark>
**Description:**
Load <WiFi.h> before use
Return the scanned network channel number.
**Function argument**
| Function argument |Type |Description |
| --- | --- | --- |
| networkItem | uint8_t | channel item |