|
https://www.tinkercad.com/things ... tastic-esboo-gaaris
// C++ code
//
/*
byte index=0;
const byte LEDs[10]={
B1111110,
B0110000,
B1101101,
B1111001,
B0110011,
B1011011,
B1011111,
B1110000,
B1111111,
B1111011,
};
void setup()
{
DDRD=B1111111;
}
void loop()
{
PORTD=LEDs[index];
index ++;
if(index==10)
{
index=0;
}
delay(1000);
}
*/
/*
byte index=0;
const byte LEDs[10]={
0xfc,//B1111110,
0x60,//B0110000,
0xda,//B1101101,
0xf2,//B1111001,
0x66,//B0110011,
0xb6,//B1011011,
0xbe,//B1011111,
0xe0,//B1110000,
0xfe,//B1111111,
0xf6,//B1111011,
};
int clockPin = 4; // Clock pin (SHCP腳位)
int latchPin = 3; // Latch pin (STCP腳位)
int dataPin = 2; // Data pin (DS腳位)
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin,clockPin,LSBFIRST,LEDs[index]);
digitalWrite(latchPin, HIGH);
delay(1000);
index ++;
if(index==10)
{
index=0;
}
}
*/
/*
const byte SEG_PIN[2]={8, 9}; // 7段顯示器的控制接腳
const byte NUM_OF_SEG = sizeof(SEG_PIN); // 7段顯示器的數量
int number=0;
byte digits[2] = {0, 0};
const byte dataPin = 2; // 74HC595序列輸入
const byte latchPin = 3; // 74HC595暫存器時脈」
const byte clockPin = 4; // 74HC595序列時脈
unsigned long previousMillis = 0;
const long interval = 1000;
const byte LEDs[10] = {
0x7E, 0x30, 0x6D, 0x79, 0x33,
0x5B, 0x5F, 0x70, 0x7F, 0x73
};
// 每隔一秒數字加1並拆解數字
void counter() {
unsigned long currentMillis = millis();
// 每隔1秒執行一次底下的條件式內容
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (++number > 99) { // number先加1,再比較
number = 0; // 若超過99則歸零
}
digits[0]= number % 10 ; // 儲存個位數字
digits[1]= number / 10 % 10 ; // 十位數字
}
}
void display(){
byte num;
// 逐一設定每個七段顯示器
for (byte i=0; i<NUM_OF_SEG; i++){
num = digits;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, LEDs[num]);
digitalWrite(latchPin, HIGH);
digitalWrite(SEG_PIN, LOW); // 點亮此顯示器
delay(5);
for (byte j=0; j<NUM_OF_SEG; j++) {
digitalWrite(SEG_PIN[j], HIGH); // 關閉所有顯示器
}
}
}
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for (byte i=0; i<NUM_OF_SEG; i++) {
pinMode(SEG_PIN, OUTPUT);
digitalWrite(SEG_PIN, HIGH);
}
}
void loop() {
counter();
display();
}
*/
const byte SEG_PIN[2]={8, 9}; // 7段顯示器的控制接腳
const byte NUM_OF_SEG = sizeof(SEG_PIN); // 7段顯示器的數量
int number=33;
byte digits[2] = {0, 0};
const byte dataPin = 2; // 74HC595序列輸入
const byte latchPin = 3; // 74HC595暫存器時脈」
const byte clockPin = 4; // 74HC595序列時脈
unsigned long previousMillis = 0;
const long interval = 1000;
const byte LEDs[10] = {
0x7E, 0x30, 0x6D, 0x79, 0x33,
0x5B, 0x5F, 0x70, 0x7F, 0x73
};
void display(){
byte num;
// 逐一設定每個七段顯示器
for (byte i=0; i<NUM_OF_SEG; i++){
num = digits;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, LEDs[num]);
digitalWrite(latchPin, HIGH);
digitalWrite(SEG_PIN, LOW); // 點亮此顯示器
delay(5);
for (byte j=0; j<NUM_OF_SEG; j++) {
digitalWrite(SEG_PIN[j], HIGH); // 關閉所有顯示器
}
}
}
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for (byte i=0; i<NUM_OF_SEG; i++)
{
pinMode(SEG_PIN, OUTPUT);
digitalWrite(SEG_PIN, HIGH);
}
}
void loop() {
digits[0]=number%10;
digits[1]=number/10%10;
display();
}
|
本帖子中包含更多資源
您需要 登錄 才可以下載或查看,沒有帳號?立即註冊
x
|