Created
February 23, 2012 07:58
-
-
Save tawashi5454/1891415 to your computer and use it in GitHub Desktop.
This file contains 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 <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