Arduino 433 自定义发射

2018/01/05 22:23
阅读数 9

 

/*
  This is a minimal sketch without using the library at all but only works for
  the 10 pole dip switch sockets. It saves a lot of memory and thus might be 
  very useful to use with ATTinys :)
  
  https://github.com/sui77/rc-switch/
*/

int RCLpin = 7;

void setup() {
    pinMode(RCLpin, OUTPUT);
}

void loop() {
    RCLswitch(0b010001000001);  // DIPs an Steckdose: 0100010000 An:01
    delay(2000);

    RCLswitch(0b010001000010);  // DIPs an Steckdose: 0100010000 Aus:10
    delay(2000);    
}

void RCLswitch(uint16_t code) {
    for (int nRepeat=0; nRepeat<6; nRepeat++) {
        for (int i=4; i<16; i++) {
            RCLtransmit(1,3);
            if (((code << (i-4)) & 2048) > 0) {
                RCLtransmit(1,3);
            } else {
                RCLtransmit(3,1);
            }
        }
        RCLtransmit(1,31);    
    }
}

void RCLtransmit(int nHighPulses, int nLowPulses) {
    digitalWrite(RCLpin, HIGH);
    delayMicroseconds( 350 * nHighPulses);
    digitalWrite(RCLpin, LOW);
    delayMicroseconds( 350 * nLowPulses);
}

  

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部