Arduino/Libraries/x10/x10.cpp
/*
	Writes a sequence of bits out.  If the sequence is not a start code,
	it repeats the bits, inverting them.
*/
Writes a sequence of bits out.  If the sequence is not a start code,
it repeats the bits, inverting them.
Writes a sequence of bits out . If the sequence is not a start code it repeats the bits inverting them .
void x10::sendBits(byte cmd, byte numBits, byte isStartCode) {
	byte thisBit;	
	for (uint8_t i=1; i<=numBits; i++) {
		waitForZeroCross();
		thisBit = !!(cmd & (1 << (numBits - i)));
		for (uint8_t phase = 0; phase < 3; phase++) {
			digitalWrite(this->dataPin, thisBit);
			delayMicroseconds(BIT_LENGTH);
			digitalWrite(this->dataPin, LOW);
			delayMicroseconds(BIT_DELAY);
		}
		if(!isStartCode) {
			waitForZeroCross();
			for (uint8_t phase = 0; phase < 3; phase++) {
				digitalWrite(this->dataPin, !thisBit);
				delayMicroseconds(BIT_LENGTH);
				digitalWrite(dataPin, LOW);
				delayMicroseconds(BIT_DELAY);
			}
		}
	}
}
void x10 :: sendBits ( byte cmd , byte numBits , byte isStartCode ) { byte thisBit ; for ( uint8_t i = 1 ; i <= numBits ; i ++ ) { waitForZeroCross ( ) ; thisBit = ! ! ( cmd & ( 1 << ( numBits - i ) ) ) ; for ( uint8_t phase = 0 ; phase < 3 ; phase ++ ) { digitalWrite ( this -> dataPin , thisBit ) ; delayMicroseconds ( BIT_LENGTH ) ; digitalWrite ( this -> dataPin , LOW ) ; delayMicroseconds ( BIT_DELAY ) ; } if ( ! isStartCode ) { waitForZeroCross ( ) ; for ( uint8_t phase = 0 ; phase < 3 ; phase ++ ) { digitalWrite ( this -> dataPin , ! thisBit ) ; delayMicroseconds ( BIT_LENGTH ) ; digitalWrite ( dataPin , LOW ) ; delayMicroseconds ( BIT_DELAY ) ; } } } }
Writes a sequence of bits out.
Writes a sequence of bits out .
// copy of command so we can shift bits // iterate the number of bits to be shifted: // wait for a zero crossing change: // shift off the last bit of the command: // repeat once for each phase: // set the data Pin: // clear the data pin: // if this command is a start code, don't // send its complement.  Otherwise do: // wait for zero crossing: // set the data pin: // clear the data pin: