Skip to content

Instantly share code, notes, and snippets.

@tawashi5454
Created February 23, 2012 07:58
Show Gist options
  • Save tawashi5454/1891415 to your computer and use it in GitHub Desktop.
Save tawashi5454/1891415 to your computer and use it in GitHub Desktop.
#include <SPI.h>
#define SHIFT_REGISTER_CS 5
void setup() {
// SPI
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
pinMode(SHIFT_REGISTER_CS, OUTPUT);
digitalWrite(SHIFT_REGISTER_CS, HIGH);
}
void loop(){
for(int i=0; i<=8; i++){
unsigned char out = 0xFF >> i;
outputToShiftRegister(out);
delay(50);
}
for(int i=8; i>=0; i--){
unsigned char out = 0xFF >> i;
outputToShiftRegister(out);
delay(50);
}
}
void outputToShiftRegister(unsigned char data){
digitalWrite(SHIFT_REGISTER_CS, LOW);
SPI.transfer(data);
digitalWrite(SHIFT_REGISTER_CS, HIGH);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment