Created
March 25, 2013 19:00
-
-
Save divanvisagie/5239658 to your computer and use it in GitHub Desktop.
Shift out multiple registers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <math.h> | |
| int latch = 10, | |
| clk = 11, | |
| data = 12; | |
| void setup(){ | |
| pinMode( latch , OUTPUT ); | |
| pinMode( clk, OUTPUT ); | |
| pinMode( data, OUTPUT ); | |
| Serial.begin( 9600 ); | |
| Serial.println( "reset" ); | |
| } | |
| void loop(){ | |
| if( Serial.available() > 0 ){ | |
| int bt = Serial.parseInt(); | |
| Serial.println( bt ); | |
| Serial.println( bt ); // register 1 | |
| Serial.println( (bt >> 16) ); // register 2 | |
| Serial.println( (bt >> 8) ); // register 3 | |
| digitalWrite( latch, LOW ); | |
| // shiftOut( data, clk, MSBFIRST, highByte(bt) ); //high is numbers on the second register | |
| // shiftOut( data, clk, MSBFIRST, lowByte(bt) ); //low is numbers on the first register | |
| //shift registers must count down from 3 to 1 | |
| shiftOut( data, clk, MSBFIRST, (bt >> 8) ); | |
| shiftOut( data, clk, MSBFIRST, (bt >> 16) ); | |
| shiftOut( data, clk, MSBFIRST, bt ); | |
| digitalWrite( latch, HIGH ); | |
| delay( 500 ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment