赤外線リモコンの仕様は比較的単純なものが多く仕様が公開されてるものもあることから、多くの方々が学習リモコンの実装に挑戦され公開されてはいる。が、仕様を限定すると対応できない機器がかなり多くなり、汎用性を考慮すると多大なメモリが必要となるなど課題も多い。
数年前、Kickstarterにてデビューしたdigisparkという極めて小さなCPUボードに興味を持ったことがきっかけでArduinoという開発環境を知る。勉強がてら赤外線リモコンでも作ってみようとは思ったもののTVリモコン等の比較的標準ぽいものはともかくエアコンなどの家電製品では仕様もパラバラでデータ・ビット数もかなり多いものがあるためデータメモリ512バイトしかないCPUでは汎用的な学習リモコンなどほぼ無理とあきらめていたが、オシロスコープで各種リモコンが出力する波形を、ずーーーーと見つめていたらなんとなく解決策が見えてきた。
赤外線リモコンの基本仕様は、ELM-ChaNさんの赤外線リモコンの通信フォーマットが詳しいので参考にしてもらいたいが、私が考えた仕様ではフィリップスのRC-5、6等のマンチェスター符号方式には対応できないものの、それ以外のパルス幅でデータビットを表す国内外の多くの機器に対応可能な方法である。(と思う...)
まず、確実にデータ解析できるようにパルスONとOFFを別けて処理することが重要である。パルス幅はリーダー部(ON/OFF)2種類、データ部(ON/OFF/LONG(1))3種類の合計5種類のみ記録。データ部はパルスONかOFFどちらかのパルス幅は常に一定、他方はデータビットにより2倍以上に変化するものとし、短いほうのパルス幅の1.5倍より大きいかどうかでリアルタイムにデータ解析&記録。その他、同一リピート・フレームや複数フレームにも対応することでコードサイズは大きくなったが作業領域を除く赤外線データ保存領域が最低20バイト~最大でも64バイトもあれば足りるというかなり省メモリなものとなり、ATtiny85でも汎用的な学習リモコンを実現することが可能となった。
あと、赤外線の波形を眺めていて気になったことが...
赤外線受信センサーは秋月で購入したSHARPのGP1UXC41QSを使用してるが、赤外線パルスの受信タイミングが遅れることは予想できたもののONとOFFに時間差があり、センサー出力のON信号幅が赤外線パルス幅よりもかなり長く見えてしまうという問題を発見。赤外線センサーの受光量に影響されるようで、弱いときでも50us、強いときだと200us程度の誤差が発生する。他社センサーではどうなのかも調べてはいないし、これが学習結果にどう影響するかも定かではないが考慮するにこしたことはなさそうである。
追記(2017-04-06)
Digisparkからも赤外線受信シールドキットが販売されてるが送信用LEDの駆動がCPUのIO直接(Max20mA)からしかできなくて実用性に乏しいためLED駆動用にトランジスタを追加したDigispark用の赤外線送受信シールドを作ってみた。
【ライブラリの使い方】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include "irremocon.h" void setup() { // 初期化 IrRemocon.begin(赤外線入力ポート, 赤外線出力ポート, 赤外線出力オフ値(HIGH or LOW)); } void loop() { int len; if (赤外線受信開始) { len = IrRemocon.scan(); if (len > 0) { // EEPROM:0番地へスキャンデータ書き込む IrRemocon.save(0, true); } else { // エラー } } if (赤外線送信開始) { // EEPROM:0番地からスキャンデータ読み込む len = IrRemocon.play(0, true); if (len == 0) { // エラー } } } |
【赤外線リモコン・ライブラリ】
2017-04-03 スキャン開始時のノイズ対策が効かなくなっていたので修正。
2017-03-20 スペル・ミスと大きなバグを見つけたので修正。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
/* * Memory Layout * * [Header] * +---+---+----------------+--------------+------------------------+ * |'I'|'R'|Version: uint8_t|Flags: uint8_t|Pulse-Table: uint16_t[5]| == 14 bytes * +---+---+----------------+--------------+------------------------+ * * Flags: b0 Sony Frame Type * b1 Leader Less Repeat Frame * * [Frame,...] * +---------------+------------------+--------------------+-----------+ * |Repeat: uint8_t|Interval: uint16_t|Bit-Length: uint16_t|Bit Data...| >= 5 bytes * +---------------+------------------+--------------------+-----------+ * | |<----+---->| * Repeat: b0-b6 Repeat Count | | * b7 Next Frame Exists +-----------------+ * */ #ifndef _IRREMOCON_H #define _IRREMOCON_H #include <Arduino.h> #define IR_ERR_TIMEOUT -1 #define IR_ERR_OVERFLOW -2 #define IR_SCAN_TIMEOUT 5000000 #define IR_SENSOR_ADJUST 100 // ref. IR SENSOR (SHARP GP1UXC41QS) #define IR_BUFFER_SIZE 64 class IrRemoconClass { private: uint8_t _buffer[IR_BUFFER_SIZE]; uint8_t _length; uint8_t _ir_input; uint8_t _ir_output; public: IrRemoconClass(); void begin(uint8_t ir_input, uint8_t ir_output, uint8_t ir_off = LOW); int scan(uint32_t timeout = IR_SCAN_TIMEOUT, uint8_t adjust = IR_SENSOR_ADJUST); int save(uint8_t *buf = NULL, boolean eeprom = false); int play(uint8_t *buf = NULL, boolean eeprom = false); String info(uint8_t *buf = NULL, boolean eeprom = false); int adjust(); }; extern IrRemoconClass IrRemocon; #endif // _IRREMOCON_H |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
#include <string.h> #ifdef __AVR__ #include <avr/wdt.h> #include <avr/eeprom.h> #include <util/delay_basic.h> #define DELAY_MICROS(t) _delay_loop_1((uint8_t)((t) * clockCyclesPerMicrosecond() * 256 / 768)) #define READ_BYTE(p, eeprom) (eeprom ? eeprom_read_byte(p) : *p) #define WRITE_BLOCK(dst, src, len, eeprom) if (eeprom) eeprom_write_block(src, dst, len); else memcpy(dst, src, len) #else #include <EEPROM.h> #define DELAY_MICROS(t) delayMicroseconds(t) #define READ_BYTE(p, eeprom) (eeprom ? EEPROM.read((int)p) : *p) #define WRITE_BLOCK(dst, src, len, eeprom) if (eeprom) for (uint8_t i = 0; i < len; ++i) EEPROM.write((int)dst + i, src[i]); else memcpy(dst, src, len) #endif #include "irremocon.h" #ifdef ESP8266 #define EEPROM_BEGIN(eeprom, buf) if (eeprom) EEPROM.begin(IR_BUFFER_SIZE + (int)buf) #define EEPROM_END(eeprom) if (eeprom) EEPROM.end() #else #define EEPROM_BEGIN(eeprom, buf) #define EEPROM_END(eeprom) #endif #define IR_2NDF_TIMEOUT 38000 // ref. SONY FORMAT and etc,... #define IR_TRAILER_TIME 4200 // ref. AEHA FORMAT and etc,... #define IR_SUBCARRIER (1000000 / 38000) // us #if defined ESP8266 #define IR_SUBCARRIER_H (IR_SUBCARRIER >> 1) - 7 #define IR_SUBCARRIER_L (IR_SUBCARRIER >> 1) + 4 #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) #define IR_SUBCARRIER_H (IR_SUBCARRIER >> 1) - 6 #define IR_SUBCARRIER_L (IR_SUBCARRIER >> 1) + 3 #else #define IR_SUBCARRIER_H (IR_SUBCARRIER >> 1) - 10 #define IR_SUBCARRIER_L (IR_SUBCARRIER >> 1) #endif #define IR_MARK "IR" #define IR_VERSION 0x10 #define IR_SONY_FRAME 1 // must be 1 #define IR_LEADERLESS2 2 // Leaderless After 2nd Frame #define IR_LEADER_H 0 #define IR_LEADER_L 1 #define IR_DATA_H 2 #define IR_DATA_L 3 #define IR_DATA_LONG 4 #define IR_MAX_WIDTHS (IR_DATA_LONG + 1) #define IR_HEADER_BYTES (4 + (IR_MAX_WIDTHS * sizeof(uint16_t))) #define IR_FRAME_BYTES 5 #define BIT_SET(buf, pos) ((buf)[(pos) >> 3] |= (1 << ((pos) & 7))) #define BIT_CLR(buf, pos) ((buf)[(pos) >> 3] &= ~(1 << ((pos) & 7))) IrRemoconClass IrRemocon; IrRemoconClass::IrRemoconClass() : _length(0) , _ir_input(-1) , _ir_output(-1) { } void IrRemoconClass::begin(uint8_t ir_input, uint8_t ir_output, uint8_t ir_off) { if ((_ir_input = ir_input) != -1) pinMode(ir_input , INPUT ); if ((_ir_output = ir_output) != -1) { pinMode(ir_output, OUTPUT); digitalWrite(ir_output, ir_off); } } int IrRemoconClass::scan(uint32_t timeout, uint8_t adjust) { uint32_t start = micros(); uint32_t next = start; uint32_t widths[IR_MAX_WIDTHS]; uint16_t counts[IR_MAX_WIDTHS]; uint16_t interval = 0; uint16_t edges = 0; uint16_t bitpos = 0; uint16_t bitlen = (IR_BUFFER_SIZE > (IR_HEADER_BYTES + IR_FRAME_BYTES) ? IR_BUFFER_SIZE - (IR_HEADER_BYTES + IR_FRAME_BYTES) : 0) << 3; uint8_t *bittbl = _buffer + IR_HEADER_BYTES + IR_FRAME_BYTES; uint8_t *bittbl0 = NULL; uint8_t written = 0; uint8_t flags = 0; uint8_t flags0 = 0; uint8_t pinval = digitalRead(_ir_input); while (true) { uint32_t td = micros() - next; if (digitalRead(_ir_input) != pinval) { uint16_t t1, ta, tb; if (edges == 0) { memset(widths, 0, sizeof(widths)); memset(counts, 0, sizeof(counts)); interval = (uint16_t)td; bitpos = 0; flags = flags0; } else { uint8_t index; if (edges & 1) td -= adjust; ta = (uint16_t)td; if (edges < IR_MAX_WIDTHS) { // Check Leader Less 2nd Frame if ((edges == 1) && bittbl0) { if (ta + (ta >> 1) < makeWord(_buffer[4], _buffer[5])) { flags |= IR_LEADERLESS2; edges += IR_DATA_H; } } index = edges - 1; } else { index = edges & 1 ? IR_DATA_H : IR_DATA_L; if (bitpos == 0) { if (counts[index] >= bitlen) return IR_ERR_OVERFLOW; tb = widths[index] / counts[index]; if (tb < ta) { t1 = tb + (tb >> 1); if (t1 < ta) { if (edges & 1) flags |= IR_SONY_FRAME; for (uint16_t i = 0; i < counts[index]; i++, bitpos++) BIT_CLR(bittbl, bitpos); BIT_SET(bittbl, bitpos); bitpos++; index = IR_DATA_LONG; } } else { t1 = ta + (ta >> 1); if (t1 < tb) { if (edges & 1) flags |= IR_SONY_FRAME; for (uint16_t i = 0; i < counts[index]; i++, bitpos++) BIT_SET(bittbl, bitpos); BIT_CLR(bittbl, bitpos); bitpos++; widths[IR_DATA_LONG] = widths[index]; counts[IR_DATA_LONG] = counts[index]; widths[index] = 0; counts[index] = 0; } } } else if ((edges & 1) == (flags & IR_SONY_FRAME)) { if (bitpos >= bitlen) return IR_ERR_OVERFLOW; if (t1 < ta) { BIT_SET(bittbl, bitpos); index = IR_DATA_LONG; } else BIT_CLR(bittbl, bitpos); bitpos++; } } widths[index] += ta; counts[index]++; } pinval = !pinval; next += td; edges++; } else if (edges && !(edges & 1)) { if (td >= IR_TRAILER_TIME) { if (bitpos) { boolean repeat = false; if (bittbl0) { if (bitpos == makeWord(bittbl0[-2], bittbl0[-1])) { uint8_t n = (bitpos >> 3); if (repeat = (memcmp(bittbl, bittbl0, n) == 0)) { if (bitpos & 7) { uint8_t m = ((1 << (bitpos & 7)) - 1); if ((bittbl[n] & m) != (bittbl0[n] & m)) repeat = false; } } } } else { uint8_t *p = _buffer; // Mark *p++ = IR_MARK[0]; *p++ = IR_MARK[1]; // Version *p++ = IR_VERSION; // Flags *p++ = 0; // Pulse Width Table for (uint8_t i = 0; i < IR_MAX_WIDTHS; ++i) { uint16_t t; if (counts[i] > 1) t = (uint16_t)((widths[i] + (counts[i] >> 1)) / counts[i]); else t = (uint16_t)widths[i]; *p++ = highByte(t); *p++ = lowByte(t); } written += IR_HEADER_BYTES; } // Flags _buffer[3] = flags0 = flags; if (repeat) { // Repeat bittbl0[-5]++; // Interval bittbl0[-4] = highByte(interval); bittbl0[-3] = lowByte(interval); } else { // next frame if (bittbl0) { // Repeat bittbl0[-5] |= 0x80; // Interval bittbl0[-4] = highByte(interval); bittbl0[-3] = lowByte(interval); } bittbl0 = bittbl; // Repeat bittbl[-5] = 0; // Interval bittbl[-4] = 0; bittbl[-3] = 0; // bit length bittbl[-2] = highByte(bitpos); bittbl[-1] = lowByte(bitpos); // bitpos = ((bitpos + 7) >> 3) + IR_FRAME_BYTES; bittbl += bitpos; written += bitpos; bitpos = bitpos << 3; bitlen -= (bitlen > bitpos ? bitpos : bitlen); timeout = IR_2NDF_TIMEOUT; } start = next; } next = start; edges = 0; } } else { if (td >= timeout) { if (bittbl0) break; return IR_ERR_TIMEOUT; } wdt_reset(); } } return _length = written; } int IrRemoconClass::save(uint8_t *buf, boolean eeprom) { EEPROM_BEGIN(eeprom, buf); if (buf || eeprom) WRITE_BLOCK(buf, _buffer, _length, eeprom); EEPROM_END(eeprom); return _length; } int IrRemoconClass::play(uint8_t *buf, boolean eeprom) { EEPROM_BEGIN(eeprom, buf); #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) const uint8_t pinval = _BV(_ir_output); #else const uint8_t pinval = digitalRead(_ir_output); #endif uint8_t h, l, *src, *p; src = p = (buf || eeprom ? buf : _buffer); // mark boolean mark = (READ_BYTE(p++, eeprom) == IR_MARK[0]); mark = mark && (READ_BYTE(p++, eeprom) == IR_MARK[1]); int rv = 0; if (mark) { // version uint8_t ver = READ_BYTE(p++, eeprom); // flags uint8_t flags = READ_BYTE(p++, eeprom); // pulse widths table uint16_t widths[IR_MAX_WIDTHS]; for (uint8_t i = 0; i < IR_MAX_WIDTHS; ++i) { h = READ_BYTE(p++, eeprom); l = READ_BYTE(p++, eeprom); widths[i] = makeWord(h, l); } boolean cframe; do { uint8_t repeat= READ_BYTE(p++, eeprom); h = READ_BYTE(p++, eeprom); l = READ_BYTE(p++, eeprom); uint16_t interval = makeWord(h, l); h = READ_BYTE(p++, eeprom); l = READ_BYTE(p++, eeprom); uint16_t bitlen = makeWord(h, l); cframe = repeat & 0x80; repeat &= 0x7F; for (uint8_t r = 0; r <= repeat; ++r) { uint32_t next = micros(); if (!(r && (flags & IR_LEADERLESS2))) { next += widths[IR_LEADER_H]; do { #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_H); PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_L); #else digitalWrite(_ir_output, !pinval); DELAY_MICROS(IR_SUBCARRIER_H); digitalWrite(_ir_output, pinval); DELAY_MICROS(IR_SUBCARRIER_L); #endif } while (0 <= (int32_t)(next - micros())); next += widths[IR_LEADER_L]; delayMicroseconds(next - micros()); } for (uint16_t i = 0; i < bitlen; ++i) { uint8_t b; if ((i & 7) == 0) b = READ_BYTE(p + (i >> 3), eeprom); boolean on = b & (1 << (i & 7)); next += widths[on && (flags & IR_SONY_FRAME) ? IR_DATA_LONG : IR_DATA_H]; do { #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_H); PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_L); #else digitalWrite(_ir_output, !pinval); DELAY_MICROS(IR_SUBCARRIER_H); digitalWrite(_ir_output, pinval); DELAY_MICROS(IR_SUBCARRIER_L); #endif } while (0 <= (int32_t)(next - micros())); next += widths[on && !(flags & IR_SONY_FRAME) ? IR_DATA_LONG: IR_DATA_L]; delayMicroseconds(next - micros()); } if ((flags & IR_SONY_FRAME) == 0) { next += widths[IR_DATA_H]; do { #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_H); PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_L); #else digitalWrite(_ir_output, !pinval); DELAY_MICROS(IR_SUBCARRIER_H); digitalWrite(_ir_output, pinval); DELAY_MICROS(IR_SUBCARRIER_L); #endif } while (0 <= (int32_t)(next - micros())); } delayMicroseconds(interval); } p += (bitlen + 7) >> 3; } while (cframe); rv = (int)p - (int)src; } EEPROM_END(eeprom); return rv; } String IrRemoconClass::info(uint8_t *buf, boolean eeprom) { EEPROM_BEGIN(eeprom, buf); String rv; uint8_t h, l, *src, *p; src = p = (buf || eeprom ? buf : _buffer); rv += "----------------- IR Info -----------------\n"; // mark boolean mark = (READ_BYTE(p++, eeprom) == IR_MARK[0]); mark = mark && (READ_BYTE(p++, eeprom) == IR_MARK[1]); if (mark) { // version uint8_t ver = READ_BYTE(p++, eeprom); // flags uint8_t flags = READ_BYTE(p++, eeprom); rv += "version "; rv += ver >> 4; rv += '.'; rv += ver & 0x0F; rv += ", flags "; rv += flags; // pulse pattern table rv += "\npulse widths "; for (uint8_t i = 0; i < IR_MAX_WIDTHS; ++i) { h = READ_BYTE(p++, eeprom); l = READ_BYTE(p++, eeprom); rv += '['; rv += makeWord(h, l); rv += ']'; } rv += '\n'; uint8_t next; do { uint8_t repeat = READ_BYTE(p++, eeprom); h = READ_BYTE(p++, eeprom); l = READ_BYTE(p++, eeprom); uint16_t interval = makeWord(h, l); h = READ_BYTE(p++, eeprom); l = READ_BYTE(p++, eeprom); uint16_t bitlen = makeWord(h, l); next = repeat & 0x80; repeat &= 0x7F; rv += "next frame "; rv += next != 0; rv += ", repeats "; rv += repeat; rv += ", interval "; rv += interval; rv += " us, data "; rv += bitlen; rv += " bits\n"; for (uint8_t r = 0; r <= repeat; ++r) { for (uint16_t i = 0; i < bitlen; ++i) { uint8_t b; if ((i & 7) == 0) b = READ_BYTE(p + (i >> 3), eeprom); if (i && ((i & 7) == 0)) rv += '-'; rv += b & (1 << (i & 7)) ? "1" : "0"; } rv += '\n'; } p += (bitlen + 7) >> 3; } while (next); rv += "total "; rv += (int)p - (int)src; rv += " bytes\n-------------------------------------------\n"; } EEPROM_END(eeprom); return rv; } uint32_t _pin_change_time; void ISR_pin_changed() { if (_pin_change_time) _pin_change_time = micros() - _pin_change_time; else _pin_change_time = micros(); } int IrRemoconClass::adjust() { #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) const uint8_t pinval = _BV(_ir_output); #else const uint8_t pinval = digitalRead(_ir_output); #endif const uint16_t pulse_time = 526; attachInterrupt(_ir_input, ISR_pin_changed, CHANGE); uint32_t adjust = 0; const uint16_t loop = 1000; for (uint16_t i = 0; i < loop; ++i) { _pin_change_time = 0; uint32_t next = micros() + pulse_time; do { #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_H); PINB = pinval; DELAY_MICROS(IR_SUBCARRIER_L); #else digitalWrite(_ir_output, !pinval); DELAY_MICROS(IR_SUBCARRIER_H); digitalWrite(_ir_output, pinval); DELAY_MICROS(IR_SUBCARRIER_L); #endif } while (0 <= (int32_t)(next - micros())); delayMicroseconds(pulse_time); adjust += _pin_change_time; } detachInterrupt(_ir_input); return (adjust / loop) - pulse_time; } |