Mọi người giúp t xem sai ở chỗ nào mà quét led 7 đoạn nó chỉ sáng nhấp nháy thôi.
(Mạch sài 4 con R 2k7, 4 con BJT PNP A1015, LED7doan K chung)
Ghép mạch như hình
Code như bên dưới
const int aPin=2;
const int bPin=3;
const int cPin=4;
const int dPin=5;
const int ePin=6;
const int fPin=7;
const int gPin=8;
const int led1Pin=9;
const int led2Pin=10;
const int led3Pin=11;
const int led4Pin=12;
unsigned char led7Hex[]={0x3f,0x06,0x5B,0x4f,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
void LED7_writeByte(unsigned char b){
if(((b>>0)& 0x01)==1){
digitalWrite(aPin,HIGH);
}else{
digitalWrite(aPin,LOW);
}
if(((b>>1)& 0x01)==1){
digitalWrite(bPin,HIGH);
}else{
digitalWrite(bPin,LOW);
}
if(((b>>2)& 0x01)==1){
digitalWrite(cPin,HIGH);
}else{
digitalWrite(cPin,LOW);
}
if(((b>>3)& 0x01)==1){
digitalWrite(dPin,HIGH);
}else{
digitalWrite(dPin,LOW);
}
if(((b>>4)& 0x01)==1){
digitalWrite(ePin,HIGH);
}else{
digitalWrite(ePin,LOW);
}
if(((b>>5)& 0x01)==1){
digitalWrite(fPin,HIGH);
}else{
digitalWrite(fPin,LOW);
}
if(((b>>6)& 0x01)==1){
digitalWrite(gPin,HIGH);
}else{
digitalWrite(gPin,LOW);
}
}
void setup(){
pinMode(aPin,OUTPUT);
pinMode(bPin,OUTPUT);
pinMode(cPin,OUTPUT);
pinMode(dPin,OUTPUT);
pinMode(ePin,OUTPUT);
pinMode(fPin,OUTPUT);
pinMode(gPin,OUTPUT);
pinMode(led1Pin,OUTPUT);
pinMode(led2Pin,OUTPUT);
pinMode(led3Pin,OUTPUT);
pinMode(led4Pin,OUTPUT);
}
void loop(){
for(int num=0;num