//------------------------------------------------------------------------------------------------------------------------- /* * IrDA receive data print program * IRreceive_print01.ino * 2020.5.28 * Original Scketch ATtiny85 IR Remote Control Receiver David Johnson-Davies - www.technoblogy.com - 3rd April 2015 ATtiny85 @ 1 MHz (internal oscillator; BOD disabled) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ //#include //ソフトウェアシリアルの設定を追記 //SoftwareSerial mySerial(3, 4); // RX(PB3:Pin2), TX(PB4:Pin3) ソフトウェアシリアルの設定を追記 // LED outputs int LED = 1; // LED indicator PB1(Pin6) volatile int NextBit; volatile unsigned long RecdData; volatile int Rcvflag = 0; //受信フラグ volatile int RcvDATA; //32bitのデータを収納する変数 char HEXprint[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'} ; //ネオピクセル #include #ifdef __AVR__ #include #endif #define PIN 1 // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800); // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel. Avoid connecting // on a live circuit...if you must, connect GND first. // Setup ********************************************** void setup() { // Set up LEDs pinMode(LED, OUTPUT); // initialize Serial Port mySerial.begin(9600); delay(500); mySerial.println("Serial connect"); // Set up Timer/Counter0 (assumes 8MHz clock) TCCR0A = 0; // No compare matches TCCR0B = 5<>4 ; // pickup upper 4 bits キーデータの最初の4bitだけ取り出している 受信したデータをシリアルコンソールに表示するコード※キーコードのみ(以下54行目〜 mySerial.print(HEXprint[Pdata]); // print in HEX Pdata = (RcvDATA & 0x0F); // pickup lower 4 bits 残りの4bitを取り出している mySerial.println(HEXprint[Pdata]); // print in HEX //ネオピクセル------ uint32_t c; //int c;を変更 理由:int=符号付24bitの整数 int b; //明るさを変えるための変数定義 switch(RcvDATA){ //虹色のカラーコードを追記 case 0x16://0 c = 0x000000; break; case 0x0C://1 c = 0xFF0000;//赤 b = 100; break; case 0x18://2 c = 0xFF6600;//オレンジ b = 100; break; case 0x5E://3 c = 0xFFFF00;//黄色 b = 100; break; case 0x08://4 c = 0x008000;//緑 b = 100; break; case 0x1C://5 c = 0x0000FF;//青 b = 100; break; case 0x5A://6 c = 0x000080;//ネイビー b = 100; break; case 0x42://7 c = 0x800080;//紫 b = 100; break; } strip.setBrightness(b); colorWipe(c,0); //ネオピクセル------ } } // *** Interrupt service routine - called on every falling edge of PB2 *** ISR(INT0_vect) { int Time = TCNT0; int Overflow = TIFR & 1<= 87) && (Time <= 114) && (Overflow == 0)) { RecdData = 0; NextBit = 0; } else if ((Time >= 80) && (Time <= 97) && (Overflow == 0)) ReceivedCode(1); // Data bit } else { if ((Time > 22) || (Overflow != 0)) NextBit = 32; // Invalid - restart else { if (Time > 13) RecdData = RecdData | ((unsigned long) 1<>16 & 0xFF; // Set DATA receivedflag for SerialPrint Rcvflag = 1; } //colorWipe(c,0);でエラーが起きたので追記 void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i