Simply stated, flippedByte=0xFF-Byte,
or if you prefer thinking in binary,
flippedByte=0b11111111-Byte
This is the circuit we are using to drive the 8 LED with the 74HX595 chip, and all this was explained in Tutorial 42.
This is the code which we developed in the video above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
int latchPin=11; int clockPin=9; int dataPin=12; int dt=1000; byte myByte=0x18; byte myByteFlipped; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(latchPin,OUTPUT); pinMode(dataPin,OUTPUT); pinMode(clockPin,OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(latchPin,LOW); shiftOut(dataPin,clockPin,LSBFIRST,myByte); digitalWrite(latchPin,HIGH); delay(dt); myByteFlipped=255-myByte; digitalWrite(latchPin,LOW); shiftOut(dataPin,clockPin,LSBFIRST,myByteFlipped); digitalWrite(latchPin,HIGH); delay(dt); } |
In all these lessons we are using the Arduino Super Starter Kit, which you can pick up HERE.