Last active
April 10, 2017 21:49
-
-
Save zinntikumugai/b06f7736e67432ae14f721178a628eb7 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
/* | |
* 7セグLEDx4 | |
*/ | |
#define DATAPIN 8 | |
#define LATCHPIN 9 | |
#define CLOCKPIN 10 | |
//7セグLED 表示用 | |
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,1}, //. | |
{ 0,0,0,0,0,0,0,0}, //all off | |
{ 1,1,1,1,1,1,1,1}, //all on | |
}; | |
//出力するセグの選択 | |
int ledselect[][4] = { | |
{ 1,0,0,0}, //A | |
{ 0,1,0,0}, //B | |
{ 0,0,1,0}, //C | |
{ 0,0,0,1}, //D | |
}; | |
void setup() { | |
pinMode(DATAPIN, OUTPUT); | |
pinMode(LATCHPIN, OUTPUT); | |
pinMode(CLOCKPIN, OUTPUT); | |
pinMode(2, OUTPUT); | |
digitalWrite(2,HIGH); | |
//SegOutPut(12); | |
delay(2000); | |
} | |
void loop() { | |
int cnt,seled,cnter; | |
int buf[4] = {0}; | |
bool b=false; | |
for(cnt=0; cnt<11; cnt++) { | |
//出力するセグの選択 | |
for(seled=0; seled<4; seled++) | |
buf[seled] = cnt + seled + ( (cnt+seled>10)? (-11):(0) ); | |
//データの出力 | |
for(cnter=0; cnter<20; cnter++) { | |
for(seled=0; seled<4; seled++) { | |
SelectSegOutPut(buf[seled], seled); | |
} | |
} | |
} | |
} | |
//選択した7セグLEDを表示 | |
void SelectSegOutPut(int led, int selectled) { | |
int cnt; | |
for(cnt=4; cnt>=0; cnt--){ | |
digitalWrite(DATAPIN, ledselect[selectled][cnt]?HIGH:LOW); | |
toggle(CLOCKPIN); | |
} | |
SegOutPut(led); | |
} | |
// 7セグLED 指定した数値を表示用をもとに出力 | |
void SegOutPut(int led) { | |
int cnt; | |
for(cnt=8; cnt>=0; cnt--) { | |
digitalWrite(DATAPIN, data[led][cnt]?HIGH:LOW); | |
toggle(CLOCKPIN); | |
} | |
toggle(LATCHPIN); | |
delay(4); | |
} | |
//指定したピンにパルスを送る | |
void toggle(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