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: LED の PWM 制御

Posted at

Ubuntu 24.04 上の Arduino IDE 2.3.2 を使いました。
ボードは、 ESP32 Dev Module です。

image.png

プログラム

led_pwm.ino
// ---------------------------------------------------------------------
//	led_pwm.ino
//
//						Jul/28/2024
// ---------------------------------------------------------------------
#define LED1 32
#define LED2 33
#define LED3 25
#define LED4 26
#define LED5 27
#define LED6 14
#define LED7 12
#define LED8 13

int leds[8] = {LED1,LED2,LED3,LED4,LED5,LED6,LED7,LED8};
int duties[8] = {1,2,4,7,11,16,22,29};
// ---------------------------------------------------------------------
void setup() {
	Serial.begin(115200);
	for (int it=0; it<8; it++)
		{
		ledcAttach(leds[it], 1000, 8);
		}
}

// ---------------------------------------------------------------------
void loop() {
	for (int it=0; it<8; it++)
		{
		ledcWrite(leds[it], duties[it]);
		Serial.print(duties[it]);
		Serial.print(" ");
		}

	Serial.println();

	delay(3000);

	shift_duties_proc(duties);
}

// ---------------------------------------------------------------------
void shift_duties_proc(int duties[])
{
	int duties_last = duties[0];

	for (int it=0; it<7; it++)
		{
		duties[it] = duties[it + 1];
		}

	duties[7] = duties_last;
}

// ---------------------------------------------------------------------
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?