Interfacing Seven Segment Display with Arduino
Circuit:
Pin Configuration:
See Also: Arduino Development Platform
Code in Action:
Code to upload:
const int a = 2;
const int b = 3;
const int c = 4;
const int d = 5;
const int e = 6;
const int f = 7;
const int g = 8;
const int dec = 9;
void setup() {
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(dec, OUTPUT);
}
void loop() {
disp(0,0,0,0,0,0,1,0); // digit 0 and decimal point
delay(500);
disp(1,0,0,1,1,1,1,1); // digit 1
delay(500);
disp(0,0,1,0,0,1,0,1); // digit 2
delay(500);
disp(0,0,0,0,1,1,0,1); // digit 3
delay(500);
disp(1,0,0,1,1,0,0,1); // digit 4
delay(500);
disp(0,1,0,0,1,0,0,1); // digit 5
delay(500);
disp(0,1,0,0,0,0,0,1); // digit 6
delay(500);
disp(0,0,0,1,1,1,1,1); // digit 7
delay(500);
disp(0,0,0,0,0,0,0,1); // digit 8
delay(500);
disp(0,0,0,0,1,0,0,1); // digit 9
delay(500);
}
void disp(int sa,int sb, int sc, int sd, int se, int sf, int sg, int sdec) {
digitalWrite(a,sa);
digitalWrite(b,sb);
digitalWrite(c,sc);
digitalWrite(d,sd);
digitalWrite(e,se);
digitalWrite(f,sf);
digitalWrite(g,sg);
digitalWrite(dec,sdec);
}
No comments:
Post a Comment