0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ESP32: Ticker の使い方

Last updated at Posted at 2022-11-28

こちらのプログラムと同じことを Ticker を使って記述しました。
ESP32: Timer 割り込み処理

Ubuntu 24.04 上の Arduino IDE 2.3.2 を使いました。

プログラム

image.png

test_ticker.ino
// ---------------------------------------------------------------
/*
	test_ticker.ino

					Nov/28/2022
*/
// ---------------------------------------------------------------
#include <Ticker.h>

volatile int interruptCounter;
int totalInterruptCounter;

Ticker tickerSet;

// ---------------------------------------------------------------
void timer_proc(int stat)
{
	interruptCounter++;
}

// ---------------------------------------------------------------
void setup()
{
	Serial.begin(115200);
	delay(3000);
	Serial.println("*** setup start ***");
	tickerSet.attach_ms(3000, timer_proc, 0);
	
	Serial.println("*** setup end ***");
}

// ---------------------------------------------------------------
void loop()
{
	if (0 < interruptCounter)
		{
		interruptCounter--;
		totalInterruptCounter++;
		 
		Serial.print("An interrupt as occurred. Total number: ");
		Serial.println(totalInterruptCounter);
		}
}

// ---------------------------------------------------------------

実行結果

$ cu -l /dev/ttyUSB0 -s 115200
Connected.
*** setup start ***
*** setup end ***
An interrupt as occurred. Total number: 1
An interrupt as occurred. Total number: 2
An interrupt as occurred. Total number: 3
An interrupt as occurred. Total number: 4
An interrupt as occurred. Total number: 5

参考ページ

ESP-WROOM-32 サンプルグログラム解説 > Ticker > Arguments

M5Stack Core2

このプログラムはそのまま M5Stack Core2 で使えます。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?