Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Accepts 8 bits of data and outputs each bit to it's corresponding pin (pins array)
- void writeByte(byte data, byte[] pins){
- // Loop through each of the 8 bits (start at zero, end at 7)
- for(byte a = 0; a < 8; a++){
- // shift the data to the right by 'a' bits and check to see if the first bit is set
- // consider if data = 0x75 (01110101 in binary)
- // the first iteration of the for loop will shift 01110101 by 0 (since a is 0 to start with)
- // since the first bit is a 1, pins[0] will output a HIGH
- // the second iteration of the for loop will shift 01110101 by 1 (since a is now 1)
- // after the shift, the data will be 0111010 (notice there are now only 7 bits!)
- // since the first bit is now a 0, pins[1] will output a LOW
- if((data >> a) & 0x01){
- digitalWrite(pins[a], HIGH);
- }else{
- digitalWrite(pins[a], LOW);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement