Last active
March 7, 2023 15:12
-
-
Save katsuyoshi/4bc97c14b89f97c42e8521642c4e8016 to your computer and use it in GitHub Desktop.
M5AtomS3でソニーテレビの赤外線リモコン信号を送信
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <IRremoteESP8266.h> | |
#include <IRsend.h> | |
#include <M5Unified.h> | |
#ifndef USE_USEBSERIAL | |
#define USBSerial Serial | |
#endif | |
static uint16_t kIrLed = 4; | |
IRsend *irsend; | |
typedef struct { | |
char *label; | |
uint64_t code; | |
uint16_t bit; | |
} ir_code_t; | |
static ir_code_t codes[] { | |
{ "電源", 0xA90, 12 }, | |
{ "画面表示", 0x5D0, 12 }, | |
{ "入力切換", 0xA50, 12 }, | |
{ "青", 0x12E9, 15 }, | |
{ "赤", 0x52E9, 15 }, | |
{ "緑", 0x32E9, 15 }, | |
{ "黄", 0x72E9, 15 }, | |
{ "番組表", 0x6D25, 15 }, | |
{ "d", 0x54E9, 15 }, | |
{ "戻る", 0x62E9, 15 }, | |
{ "オプション", 0x36E9, 15 }, | |
{ "デジタル", 0x26E9, 15 }, | |
{ "BS", 0x1AE9, 15 }, | |
{ "1", 0x10, 12 }, | |
{ "2", 0x810, 12 }, | |
{ "3", 0x410, 12 }, | |
{ "4", 0xC10, 12 }, | |
{ "5", 0x210, 12 }, | |
{ "6", 0xA10, 12 }, | |
{ "7", 0x610, 12 }, | |
{ "8", 0xE10, 12 }, | |
{ "9", 0x110, 12 }, | |
{ "10", 0x910, 12 }, | |
{ "11", 0x510, 12 }, | |
{ "12", 0xD10, 12 }, | |
{ "音量+", 0x490, 12 }, | |
{ "音量-", 0xC90, 12 }, | |
{ "チャンネル+", 0x90, 12 }, | |
{ "チャンネル-", 0x890, 12 }, | |
{ "消音", 0x290, 12 }, | |
}; | |
static int count_of_codes = sizeof(codes) / sizeof(codes[0]); | |
static int code_index = 0; | |
static bool btna_holding = false; | |
static void display() { | |
M5.Display.clear(); | |
M5.Display.setCursor(1, 1); | |
M5.Display.print(codes[code_index].label); | |
} | |
void setup() { | |
M5.begin(); | |
int textsize = M5.Display.height() / 80; | |
if (textsize == 0) { textsize = 1; } | |
M5.Display.setTextSize(textsize); | |
M5.Display.setFont(&fonts::lgfxJapanGothic_16); | |
display(); | |
switch(M5.getBoard()) { | |
case m5gfx::board_t::board_M5StickC: | |
kIrLed = 9; | |
break; | |
case m5gfx::board_t::board_M5AtomS3: | |
kIrLed = 6; //4; | |
break; | |
} | |
irsend = new IRsend(kIrLed); | |
USBSerial.begin(115200); | |
irsend->begin(); | |
} | |
void loop() { | |
M5.update(); | |
if (M5.BtnA.wasClicked()) { | |
code_index = (code_index + 1) % count_of_codes; | |
USBSerial.printf("index = %d\r\n", (int)code_index); | |
display(); | |
} | |
if (btna_holding == false && M5.BtnA.wasHold()) { | |
btna_holding = true; | |
USBSerial.printf("Holding\r\n"); | |
irsend->sendSony(codes[code_index].code, codes[code_index].bit, 3/* repeats */); | |
delay(2000); | |
} | |
if (btna_holding == true && M5.BtnA.wasReleased()) { | |
btna_holding = false; | |
USBSerial.printf("Release\r\n"); | |
} | |
delay(50); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[platformio] | |
default_envs = ATOMS3 | |
;default_envs = M5STICK-C | |
[env:ATOMS3] | |
platform = espressif32@5.2.0 | |
framework = arduino | |
platform_packages = platformio/framework-arduinoespressif32@^3.20005.220925 | |
board = esp32-s3-devkitc-1 | |
lib_ldf_mode = deep | |
monitor_speed = 115200 | |
upload_speed = 1500000 | |
board_build.f_cpu = 240000000L | |
board_build.f_flash = 80000000L | |
board_build.flash_mode = dio | |
build_flags = | |
-DCORE_DEBUG_LEVEL=3 | |
-DUSE_USEBSERIAL | |
-Iinclude | |
lib_deps = | |
crankyoldgit/IRremoteESP8266@^2.8.4 | |
m5stack/M5Unified@^0.1.4 | |
[env:M5STICK-C] | |
platform = espressif32 | |
board = m5stick-c | |
framework = arduino | |
monitor_speed = 115200 | |
lib_deps = | |
crankyoldgit/IRremoteESP8266@^2.8.4 | |
m5stack/M5Unified@^0.1.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment