Skip to content

Instantly share code, notes, and snippets.

@divanvisagie
Created March 25, 2013 19:00
Show Gist options
  • Select an option

  • Save divanvisagie/5239658 to your computer and use it in GitHub Desktop.

Select an option

Save divanvisagie/5239658 to your computer and use it in GitHub Desktop.
Shift out multiple registers
#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