pdf-icon

Arduino入門

2. デバイス&サンプル

Basic/Fire/Gray/M5GO Ticker

検出したネットワークのチャンネル番号を取得<Ticker.h>

once()

機能です:

設定した時刻点(s)で一回だけコールバック関数を実行する。

原型関数です:

void once(float seconds, callback_t callback)

パラメータです タイプです 記述します
seconds float 実行時間を設定します
callback callback_t 反転関数です

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <M5Stack.h>
#include <Ticker.h>
Ticker ticker; // 建立Ticker用于实现定时功能. Build Ticker to implement timing function
// 在Tinker对象控制下,此函数将会定时执行.
// Under the control of the Tinker object, this function will be executed periodically
void sayHi() {
Serial.print("Hi,Ticker!");
}
void setup() {
M5.begin();
// 第三秒时调用sayHi函数一次. The sayHi function is called once at the third second
ticker.once(3, sayHi);
}
void loop() {
// 在Tinker对象控制下,M5Stack可以定时执行其它任务.
// Under the control of Tinker object, M5Stack can perform other tasks periodically
Serial.println("Ticker");
delay(1000);
}

once_ms()

機能です:

設定した時刻点(ms)でコールバック関数を一回だけ実行します。

原型関数です:

void once_ms(uint32_t milliseconds, callback_t callback)

パラメータです タイプです 記述します
milliseconds float 実行時間を設定します
callback callback_t 反転関数です

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <M5Stack.h>
#include <Ticker.h>
Ticker ticker; // 建立Ticker用于实现定时功能. Build Ticker to implement timing function
// 在Tinker对象控制下,此函数将会定时执行.
// Under the control of the Tinker object, this function will be executed periodically
void sayHi() {
Serial.println("Hi,Ticker!");
}
void setup() {
M5.begin();
// 第3000ms时调用sayHi函数一次. Call the sayHi function once at 3000ms
ticker.once_ms(3, sayHi);
}
void loop() {
// 在Tinker对象控制下,M5Stack可以定时执行其它任务.
// Under the control of Tinker object, M5Stack can perform other tasks periodically
Serial.println("Ticker");
delay(1000);
}

attach()

機能です:

指定の間隔(s)ごとにコールバック関数を実行します。

原型関数です:

void attach(float seconds, callback_t callback)

パラメータです タイプです 記述します
seconds float 秒です
callback callback_t コールバック関数の名前です

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <M5Stack.h>
#include <Ticker.h>
Ticker ticker; // 建立Ticker用于实现定时功能. Build Ticker to implement timing function
int count; // 计数用变量. variable for counting
// 在Tinker对象控制下,此函数将会定时执行. Under the control of the Tinker
// object, this function will be executed periodically
void sayHi() {
count++;
Serial.print("Hi ");
Serial.println(count);
}
void setup() {
M5.begin();
// 每隔一秒钟调用sayHi函数一次. Call the sayHi function every one second
ticker.attach(1, sayHi);
}
void loop() {
// 在Tinker对象控制下,M5Stack可以定时执行其它任务. Under the control of
// Tinker object, M5Stack can perform other tasks periodically
Serial.println("Ticker");
delay(3000);
}

attach_ms()

機能です:

指定の間隔(ms)ごとにコールバック関数を実行します。

原型関数です:

void attach_ms(uint32_t milliseconds, callback_t callback)

パラメータです タイプです 記述します
milliseconds float 秒です
callback callback_t コールバック関数の名前です

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#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() {
}

attach()

機能です:

指定の間隔(s)ごとに引数を持つコールバック関数を実行します。

原型関数です:

void attach(float seconds, void (*callback)(TArg), TArg arg)

パラメータです タイプです 記述します
seconds float 秒です
*callback callback_t パラメーター付きコールバック関数です
TArg arg 関数の引数です

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <M5Stack.h>
#include <Ticker.h>
Ticker tickerSetHigh; // 建立Ticker用于实现定时功能. Build Ticker to implement timing function
Ticker tickerSetLow;
void display(int number) {
M5.Lcd.setCursor(0, 0);
M5.Lcd.print(number);
}
void setup() {
M5.begin();
tickerSetLow.attach(1, display, 0); //每隔1s执行一次带参数的回调函数. Execute a callback function with parameters every 1s
tickerSetHigh.attach(2, display, 1);
}
void loop() {}

attach_ms()

機能です:

指定の間隔(ms)ごとに引数を持つコールバック関数を実行します。

原型関数です:

void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)

パラメータです タイプです 記述します
milliseconds float 秒です
*callback callback_t パラメーター付きコールバック関数です
TArg arg パラメータです

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#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() {}
On This Page