我有一個小型7段led顯示屏,我想知道是否可以讓它顯示一分鐘的最後一位數字。下載了Arduino的時間庫,我嘗試了幾種方法,使用switch case和if if if,但都得到相同的結果,LED顯示屏只顯示0 ...你能指出我做錯了什麼嗎?Arduino無法讓時間正確嗎?
#include <Time.h>
#include <TimeLib.h>
int led1=2;
int led2=3;
int led3=4;
int led4=5;
int led5=6;
int led6=7;
int led7=8;
int led8=9;
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(led5,OUTPUT);
pinMode(led6,OUTPUT);
pinMode(led7,OUTPUT);
pinMode(led8,OUTPUT);
}
void loop(){
time_t t=minute();
int digit1=t%10;
if(digit1==1){
digitalWrite(led5, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==2)
{
digitalWrite(led6, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
} else if(digit1==3)
{
digitalWrite(led4, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led2, HIGH);
}else if(digit1==4)
{
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==5)
{
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led2, HIGH);
}else if(digit1==6)
{
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==7)
{
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led3, HIGH);
}else if(digit1==8)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
}else if(digit1==9)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
}else if(digit1==0)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
}
}
我試過你的方法重新佈線,並將各自的LED拉低,但無濟於事。問題是't'分配的值。我註釋掉了開關盒/是否還有零件,並試圖在串行監視器上打印值,而這個值始終爲零。我還會添加一個串口監視器的照片。 –
是,則該顯示器被共同陰極,顯示實際上是一個4位數字顯示,具有用於每個數字的陰極,然後陽極爲每個LED段(http://raspi.tv/wp-content/uploads/2015/ 11/7SEG-引出線-annotated_1500.jpg)。但問題是不與顯示器,是與時間變量t,以及它返回...... –
即時得到與上述程序正確的輸出。要查看你必須等待一分鐘,然後,然後你會看到從0到1的變化我試圖使用'time_t的T =第二()的變化;'和每月的第二個拿到輸出。 –