Skip to content

Instantly share code, notes, and snippets.

@zinntikumugai
Created February 25, 2017 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zinntikumugai/0b4ae2acb3b5de69adf9343c9450d18c to your computer and use it in GitHub Desktop.
Save zinntikumugai/0b4ae2acb3b5de69adf9343c9450d18c to your computer and use it in GitHub Desktop.
/*
* シフトレジスタテスト
*/
#define DATAPIN 8
#define LATCHPIN 9
#define CLOCKPIN 10
int data[][8] = {
{ 1,1,1,1,1,1,0,0}, //0
{ 0,1,1,0,0,0,0,0}, //1
{ 1,1,0,1,1,0,1,0}, //2
{ 1,1,1,1,0,0,1,0}, //3
{ 0,1,1,0,0,1,1,0}, //4
{ 1,0,1,1,0,1,1,0}, //5
{ 1,0,1,1,1,1,1,0}, //6
{ 1,1,1,0,0,0,0,0}, //7
{ 1,1,1,1,1,1,1,0}, //8
{ 1,1,1,1,0,1,1,0}, //9
{ 0,0,0,0,0,0,0,0}, // all off
{ 1,1,1,1,1,1,1,1}, //all on
};
void setup() {
pinMode(DATAPIN, OUTPUT);
pinMode(LATCHPIN, OUTPUT);
pinMode(CLOCKPIN, OUTPUT);
pinMode(13, OUTPUT);
output(3);
delay(2000);
}
void loop() {
int cnt;
for( cnt=0; cnt<10; cnt++) {
output(10);
output(cnt);
delay(500);
}
}
//データ出力
void output(int selectled) {
int cnt;
for(cnt=8; cnt>=0; cnt--) {
digitalWrite(DATAPIN, data[selectled][cnt]?HIGH:LOW); //1bit文のデータ状態を指定
onoff( CLOCKPIN);
onoff(13);
}
onoff( LATCHPIN );
}
void onoff(int Pin) {
digitalWrite(Pin, LOW);
digitalWrite(Pin, HIGH);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment