Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////
- // Author: Sanel Smajlovic
- // Licence: N/A do w/e you please
- //
- // Dispaly Setup:
- // aaa
- // f b
- // f b
- // ggg
- // e c
- // e c
- // ddd h
- //
- // Setup for common cathode. For common anode invert the 1's and 0's in table below***
- // You should use resistors(220 Ohm suggested for 5V boards) for each connection beside ground for uniform brightness
- //Pin Setup: Change accordingly
- int a=6;
- int b=5;
- int c=12;
- int d=11;
- int e=10;
- int f=8;
- int g=9;
- int h=13;
- int segs[]={a,b,c,d,e,f,g}; //Simple Array
- byte segmap[][7]={{1,1,1,1,1,1,0}, //0 ***Invert the 1's and 0's for common anode
- {0,1,1,0,0,0,0}, //1
- {1,1,0,1,1,0,1}, //2
- {1,1,1,1,0,0,1}, //3
- {0,1,1,0,0,1,1}, //4
- {1,0,1,1,0,1,1}, //5
- {1,0,1,1,1,1,1}, //6
- {1,1,1,0,0,0,0}, //7
- {1,1,1,1,1,1,1}, //8
- {1,1,1,1,0,1,1}, //9
- {1,0,0,1,1,1,1}}; //E - Error code
- // the setup routine runs once when you press reset:
- void setup() {
- for(int i=0;i<sizeof(segs);i++){ //Iterate through all the pins and set them as outputs
- pinMode(segs[i], OUTPUT);
- }
- pinMode(h,OUTPUT); //Lets not forget the dot
- }
- // the loop routine runs over and over again forever:
- void loop() {
- for(int i=0;i<=10;i++){ //Iteratate from 0-9, any number less than 0 or greated than 9 will display "E" for error.
- disp7seg(i);
- delay(1000); //1000 millisecond(1 second) pause
- }
- disp7segDot(HIGH); //Turn on the dot and turn it off after 0.5 seconds
- delay(500);
- disp7segDot(LOW);
- }
- //Dot control function
- void disp7segDot(byte state){
- digitalWrite(h,state);
- }
- //7 segment driver function
- void disp7seg(int num){
- for(int i=0;i<7;i++){ //Iterate through all the segments
- if(num>=0 && num<10){ //Check for valid number
- digitalWrite(segs[i],segmap[num][i]); //Light the segment for corrosponding number
- }
- else{
- digitalWrite(segs[i],segmap[10][i]); //Light the segment to display "E"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement