Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

Close

led-display-arduino-4-digit-7-segment | Electronics Lab

led-display-arduino-4-digit-7-segment
Version 1 - Last update: Oct 17, 2015

//**********************************************************************************************************// //Interesting efects //segments int a = 2; int b = 3; int c = 4; int d = 5; int e = 6; int f = 7; int g = 8; int p = 13; //digits int d4 = 9; int d3 = 10; int d2 = 11; int d1 = 12; //other int del = 50; int buttoncount = 0; int loopcount = 0;

void setup() { pinMode(d1, OUTPUT); pinMode(d2, OUTPUT); pinMode(d3, OUTPUT); pinMode(d4, OUTPUT); pinMode(a, OUTPUT); pinMode(b, OUTPUT); pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT); pinMode(p, OUTPUT); digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(p, HIGH); }

void loop() { roulette(10); delay(100); zigzag(20); delay(100); circles(5); delay(100); }

void pickDigit(int x) { digitalWrite(d1, LOW); digitalWrite(d2, LOW); digitalWrite(d3, LOW); digitalWrite(d4, LOW);

switch(x) { case 1: digitalWrite(d1, HIGH); break; case 2: digitalWrite(d2, HIGH); break; case 3: digitalWrite(d3, HIGH); break; default: digitalWrite(d4, HIGH); break; } }

void clearLEDs() { digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(p, LOW); }

void roulette(int x) { loopcount = 0; while (loopcount < x) { digitalWrite(a, HIGH); pickDigit(1); delay(del); pickDigit(2); delay(del); pickDigit(3); delay(del); pickDigit(4); delay(del); digitalWrite(a, LOW); digitalWrite(b, HIGH); delay(del); digitalWrite(b, LOW); digitalWrite(c, HIGH); delay(del); digitalWrite(c, LOW); digitalWrite(d, HIGH); delay(del); pickDigit(3); delay(del); pickDigit(2); delay(del); pickDigit(1); delay(del); digitalWrite(d, LOW); digitalWrite(e, HIGH); delay(del); digitalWrite(e, LOW); digitalWrite(f, HIGH); delay(del); clearLEDs(); loopcount++; } }

void zigzag(int x) { loopcount = 0; while(loopcount < x) { digitalWrite(a, HIGH); pickDigit(1); delay(del); pickDigit(2); delay(del); pickDigit(3); delay(del); pickDigit(4); delay(del); digitalWrite(a, LOW); digitalWrite(b, HIGH); delay(del); digitalWrite(b, LOW); digitalWrite(g, HIGH); delay(del); pickDigit(3); delay(del); pickDigit(2); delay(del); pickDigit(1); delay(del); digitalWrite(g, LOW); digitalWrite(e, HIGH); delay(del); digitalWrite(e, LOW); digitalWrite(d, HIGH); delay(del); pickDigit(2); delay(del); pickDigit(3); delay(del); pickDigit(4); delay(del); digitalWrite(d, LOW); digitalWrite(c, HIGH); delay(del); digitalWrite(c, LOW); digitalWrite(g, HIGH); delay(del); pickDigit(3); delay(del); pickDigit(2); delay(del); pickDigit(1); delay(del); digitalWrite(g, LOW); digitalWrite(f, HIGH); delay(del); clearLEDs(); loopcount++; } }

void circles(int x) { loopcount = 0; while (loopcount < x) { digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); pickDigit(1); delay(250); digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(f, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); pickDigit(2); delay(250); digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(f, HIGH); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); pickDigit(3); delay(250); digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(f, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); pickDigit(4); delay(250); clearLEDs(); loopcount++; } } //**********************************************************************************************************//

Comments disabled