
Arduino入門
Arduino Nesso N1 の IR ドライバサンプルプログラム。本サンプルは Arduino-IRremote - Lib を使用して NEC コーディングを実現しています。
#define DISABLE_CODE_FOR_RECEIVER // 各送信後に受信機を再起動しないようにします。
// 受信機機能を使用しない場合、約450バイトのプログラムメモリと
// 約269バイトのRAMを節約します。
#define SEND_PWM_BY_TIMER
#define IR_TX_PIN 9
#include "M5Unified.h"
#include <IRremote.hpp> // ライブラリをインクルード
// IRremote: https://github.com/Arduino-IRremote/Arduino-IRremote
uint8_t sCommand = 0x34;
uint8_t sRepeats = 0;
void setup() {
auto cfg = M5.config();
M5.begin(cfg);
M5.Display.setRotation(1);
M5.Display.setTextColor(GREEN);
M5.Display.setTextDatum(middle_center);
M5.Display.setTextFont(&fonts::Orbitron_Light_24);
M5.Display.setTextSize(1);
IrSender.begin(DISABLE_LED_FEEDBACK); // IR_SEND_PIN を送信ピンとして開始
IrSender.setSendPin(IR_TX_PIN);
}
void loop() {
Serial.println();
Serial.print(F("Send now: address=0x1111, command=0x"));
Serial.print(sCommand, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats);
Serial.println();
M5.Display.clear();
M5.Display.drawString("IR NEC SEND", M5.Display.width() / 2,
M5.Display.height() / 2 - 40);
M5.Display.drawString("ADDR:0x1111", M5.Display.width() / 2,
M5.Display.height() / 2);
M5.Display.drawString("CMD:0x" + String(sCommand, HEX),
M5.Display.width() / 2,
M5.Display.height() / 2 + 40);
Serial.println(F("Send standard NEC with 16 bit address"));
M5.Display.fillCircle(32, 105, 8, GREEN);
IrSender.sendNEC(0x1111, sCommand, sRepeats);
// IrSender.sendOnkyo(0x1111, 0x2223, sRepeats);
/*
* 送信値をインクリメント
*/
sCommand += 1;
delay(500);
M5.Display.fillCircle(32, 105, 8, YELLOW);
delay(500);
}