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: 外部割り込み

Posted at

ハード

抵抗内蔵の LED を 緑 2個、赤 2個
タクトスイッチ 2個
抵抗 2個 (タクトスイッチのプルアップに使用)

esp32_mar0101.jpg

プログラム

gpio_test03.ino
// ---------------------------------------------------------------------
/*
	gpio_test03.ino
						Mar/01/2025
*/
// ---------------------------------------------------------------------
#define	PROGRAM	"gpio_test03.ino"
#define	VERSION	"2025-03-01 PM 15:03"

#define LED_12 12
#define LED_13 13
#define LED_14 14
#define LED_26 26
#define LED_27 27

#define SW_A 32
#define SW_B 33

volatile bool request_aa = false;
volatile bool request_bb = false;
// ---------------------------------------------------------------------
void setup()
{
	pinMode(LED_12, OUTPUT);
	pinMode(LED_27, OUTPUT);
	pinMode(LED_13, OUTPUT);
	pinMode(LED_26, OUTPUT);
	digitalWrite (LED_12, LOW) ;
	digitalWrite (LED_27, HIGH) ;
	digitalWrite (LED_13, LOW) ;
	digitalWrite (LED_26, HIGH) ;

	pinMode(SW_A, INPUT_PULLUP);
	attachInterrupt(SW_A, blink_aa_proc, FALLING);
	pinMode(SW_B, INPUT_PULLUP);
	attachInterrupt(SW_B, blink_bb_proc, FALLING);

	delay(1000);
	Serial.println(PROGRAM);
	Serial.println(VERSION);
	Serial.println("*** setup end ***");
}

// ---------------------------------------------------------------------
void blink_aa_proc()
{
	request_aa = true;
}

// ---------------------------------------------------------------------
void blink_bb_proc()
{
	request_bb = true;
}

// ---------------------------------------------------------------------
void loop()
{
	if (request_aa)
		{
		digitalWrite (LED_27, !digitalRead(LED_27)) ;
		digitalWrite (LED_12, !digitalRead(LED_12)) ;
		delay(250);
		request_aa = false;
		}

	if (request_bb)
		{
		digitalWrite (LED_26, !digitalRead(LED_26)) ;
		digitalWrite (LED_13, !digitalRead(LED_13)) ;
		delay(250);
		request_bb = false;
		}

	delay(100);
}

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

Arduino IDE 2.3.4

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?