Exemplo n.º 1
0
void LegoIr::send()
{
    uint8_t i, j;
    uint16_t message = _nib1 << 12 | _nib2 << 8 | _nib3 << 4 | CHECKSUM();
    for(i = 0; i < 6; i++)
    {
        pause(i);
        start_stop_bit();
        for(j = 0; j < 16; j++) {
            send_bit();
            delayMicroseconds((0x8000 & (message << j)) != 0 ? HIGH_PAUSE : LOW_PAUSE);
        }
        start_stop_bit();
    }
}
Exemplo n.º 2
0
void LEGOPowerFunctions::pf_send(int code1, int code2) {

    if (code1 == delay_code1 && code2 == delay_code2) 
    {
        if (messagecount < 4)
            messagecount++;
    } else 
    {
        delay_code1 = code1;
        delay_code2 = code2;
        messagecount = 0;
    }
	
    cli(); // make it uninterruptable
    start_stop_bit();

    int x = 128;
    while (x) {
        oscillationWrite(_IR_Pin, 156);

        if (code1 & x) //high bit
            delayMicroseconds(546);
        else //low bit
            delayMicroseconds(260);

        x >>= 1; //next bit
    }

    x = 128;
    while (x) {
        oscillationWrite(_IR_Pin, 156);

        if (code2 & x) // high bit
            delayMicroseconds(546);
        else //low bit
            delayMicroseconds(260);

        x >>= 1; //next bit
    }
    start_stop_bit();
    sei();

}