亚博智能论坛  
  
查看: 807|回复: 2

可以扩展红外遥控吗,怎么扩展?

  [复制链接]

该用户从未签到

2

主题

2

帖子

11

积分

新手上路

Rank: 1

积分
11
发表于 2017-7-27 09:23:51 | 显示全部楼层 |阅读模式
可以扩展红外遥控吗,怎么扩展?
回复

使用道具 举报

  • TA的每日心情
    开心
    2017-7-27 10:11
  • 8

    主题

    22

    帖子

    53

    积分

    新手上路

    Rank: 1

    积分
    53
    发表于 2017-7-27 10:11:26 | 显示全部楼层
    可以,1838红外一体化接收头
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    擦汗
    2017-7-27 10:25
  • 1

    主题

    10

    帖子

    19

    积分

    新手上路

    Rank: 1

    积分
    19
    发表于 2017-7-27 10:24:51 | 显示全部楼层
    红外遥控介绍与接收 http://blog.sina.com.cn/s/blog_7e7fa4c80102vmbc.html
    红外编码与解码——GREE格力遥控
    http://blog.sina.com.cn/s/blog_7e7fa4c80102vmbd.html
    http://blog.sina.com.cn/s/blog_7e7fa4c80102vmv3.html

    电视遥控也可以,把程序烧录进去就可以了
    1. #include <IRremote.h>

    2. int RECV_PIN = 11;
    3. int BUTTON_PIN = 7;
    4. int STATUS_PIN = 8;

    5. IRrecv irrecv(RECV_PIN);
    6. IRsend irsend;

    7. decode_results results;

    8. void setup()
    9. {
    10.   Serial.begin(9600);
    11.   irrecv.enableIRIn(); // Start the receiver
    12.   pinMode(BUTTON_PIN, INPUT);
    13.   pinMode(STATUS_PIN, OUTPUT);
    14. }

    15. // Storage for the recorded code
    16. int codeType = -1; // The type of code
    17. unsigned long codeValue; // The code value if not raw
    18. unsigned int rawCodes[RAWBUF]; // The durations if raw
    19. int codeLen; // The length of the code
    20. int toggle = 0; // The RC5/6 toggle state

    21. // Stores the code for later playback
    22. // Most of this code is just logging
    23. void storeCode(decode_results *results) {
    24.   codeType = results->decode_type;
    25.   int count = results->rawlen;
    26.   if (codeType == UNKNOWN) {
    27.     Serial.println("Received unknown code, saving as raw");
    28.     codeLen = results->rawlen - 1;
    29.     // To store raw codes:
    30.     // Drop first value (gap)
    31.     // Convert from ticks to microseconds
    32.     // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
    33.     for (int i = 1; i <= codeLen; i++) {
    34.       if (i % 2) {
    35.         // Mark
    36.         rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
    37.         Serial.print(" m");
    38.       }
    39.       else {
    40.         // Space
    41.         rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
    42.         Serial.print(" s");
    43.       }
    44.       Serial.print(rawCodes[i - 1], DEC);
    45.     }
    46.     Serial.println("");
    47.   }
    48.   else {
    49.     if (codeType == NEC) {
    50.       Serial.print("Received NEC: ");
    51.       if (results->value == REPEAT) {
    52.         // Don't record a NEC repeat value as that's useless.
    53.         Serial.println("repeat; ignoring.");
    54.         return;
    55.       }
    56.     }
    57.     else if (codeType == GREE) {
    58.       Serial.print("Received GREE: ");
    59.     }
    60.     else if (codeType == SONY) {
    61.       Serial.print("Received SONY: ");
    62.     }
    63.     else if (codeType == PANASONIC) {
    64.       Serial.print("Received PANASONIC: ");
    65.     }
    66.     else if (codeType == JVC) {
    67.       Serial.print("Received JVC: ");
    68.     }
    69.     else if (codeType == RC5) {
    70.       Serial.print("Received RC5: ");
    71.     }
    72.     else if (codeType == RC6) {
    73.       Serial.print("Received RC6: ");
    74.     }
    75.     else {
    76.       Serial.print("Unexpected codeType ");
    77.       Serial.print(codeType, DEC);
    78.       Serial.println("");
    79.     }
    80.     Serial.println(results->value, HEX);
    81.     codeValue = results->value;
    82.     codeLen = results->bits;
    83.   }
    84. }

    85. void sendCode(int repeat) {
    86.   if (codeType == NEC) {
    87.     if (repeat) {
    88.       irsend.sendNEC(REPEAT, codeLen);
    89.       Serial.println("Sent NEC repeat");
    90.     }
    91.     else {
    92.       irsend.sendNEC(codeValue, codeLen);
    93.       Serial.print("Sent NEC ");
    94.       Serial.println(codeValue, HEX);
    95.     }
    96.   }
    97.   else if (codeType == GREE){
    98.     irsend.sendGree(codeValue, codeLen);
    99.     Serial.print("Sent NEC ");
    100.     Serial.println(codeValue, HEX);  
    101.   }
    102.   else if (codeType == SONY) {
    103.     irsend.sendSony(codeValue, codeLen);
    104.     Serial.print("Sent Sony ");
    105.     Serial.println(codeValue, HEX);
    106.   }
    107.   else if (codeType == PANASONIC) {
    108.     irsend.sendPanasonic(codeValue, codeLen);
    109.     Serial.print("Sent Panasonic");
    110.     Serial.println(codeValue, HEX);
    111.   }
    112.   else if (codeType == JVC) {
    113.     irsend.sendPanasonic(codeValue, codeLen);
    114.     Serial.print("Sent JVC");
    115.     Serial.println(codeValue, HEX);
    116.   }
    117.   else if (codeType == RC5 || codeType == RC6) {
    118.     if (!repeat) {
    119.       // Flip the toggle bit for a new button press
    120.       toggle = 1 - toggle;
    121.     }
    122.     // Put the toggle bit into the code to send
    123.     codeValue = codeValue & ~(1 << (codeLen - 1));
    124.     codeValue = codeValue | (toggle << (codeLen - 1));
    125.     if (codeType == RC5) {
    126.       Serial.print("Sent RC5 ");
    127.       Serial.println(codeValue, HEX);
    128.       irsend.sendRC5(codeValue, codeLen);
    129.     }
    130.     else {
    131.       irsend.sendRC6(codeValue, codeLen);
    132.       Serial.print("Sent RC6 ");
    133.       Serial.println(codeValue, HEX);
    134.     }
    135.   }
    136.   else if (codeType == UNKNOWN /* i.e. raw */) {
    137.     // Assume 38 KHz
    138.     irsend.sendRaw(rawCodes, codeLen, 38);
    139.     Serial.println("Sent raw");
    140.   }
    141. }

    142. int lastButtonState;

    143. void loop() {
    144.   // If button pressed, send the code.
    145.   int buttonState = digitalRead(BUTTON_PIN);

    146.   if (lastButtonState == HIGH && buttonState == LOW) {
    147.     Serial.println("Released");
    148.     irrecv.enableIRIn(); // Re-enable receiver
    149.   }

    150.   if (buttonState==LOW) {
    151.     Serial.println("Pressed, sending");
    152.     digitalWrite(STATUS_PIN, LOW);
    153.     sendCode(lastButtonState == buttonState);
    154.     digitalWrite(STATUS_PIN, HIGH);
    155.     delay(50); // Wait a bit between retransmissions
    156.   }
    157.   else if (irrecv.decode(&results)) {
    158.     digitalWrite(STATUS_PIN, LOW);
    159.     storeCode(&results);
    160.     irrecv.resume(); // resume receiver
    161.     digitalWrite(STATUS_PIN, HIGH);
    162.   }
    163.   lastButtonState = buttonState;
    164.   

    165. }
    复制代码
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    快速回复 返回顶部 返回列表