Components and supplies
7 Segment LED Display, Red
Jumper wires (generic)
Resistor 330 ohm
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
the code:
arduino
1/* 2 Showing numbers, chars and phrases 3 A 4 (seg[0] in this project) 5 --- 6F (seg[5] in this 7 project) | | B (seg[1] in this project) 8 | | 9 10 --- G (seg[6] in this project) 11E (seg[4] in this 12 project) | | 13 | | C (seg[2] in this project) 14 15 --- . dot or dicimal (seg[7] in this project) 16 D 17 (seg[3] in this project) 18 19 */ 20#define A 8 21#define B 7 22#define C 6 23#define 24 D 5 25#define E 4 26#define F 3 27#define G 2 28#define DP 9 // decimal 29#define 30 common_cathode 0 31#define common_anode 1 32bool segMode = common_cathode; // 33 set this to your segment type, my segment is common_cathode 34int seg[] {A,B,C,D,E,F,G,DP}; 35 // segment pins 36byte chars = 35; // max value in the array "Chars" 37 38byte 39 Chars[35][9] { 40 {'0',1,1,1,1,1,1,0,0},//0 41 {'1',0,1,1,0,0,0,0,0},//1 42 43 {'2',1,1,0,1,1,0,1,0},//2 44 {'3',1,1,1,1,0,0,1,0},//3 45 46 {'4',0,1,1,0,0,1,1,0},//4 47 {'5',1,0,1,1,0,1,1,0},//5 48 49 {'6',1,0,1,1,1,1,1,0},//6 50 {'7',1,1,1,0,0,0,0,0},//7 51 52 {'8',1,1,1,1,1,1,1,0},//8 53 {'9',1,1,1,1,0,1,1,0},//9 54 55 {'a',1,1,1,0,1,1,1,0},//A/10 56 {'b',0,0,1,1,1,1,1,0},//b/11 57 58 {'c',1,0,0,1,1,1,0,0},//C/12 59 {'d',0,1,1,1,1,0,1,0},//d/13 60 61 {'e',1,0,0,1,1,1,1,0},//E/14 62 {'f',1,0,0,0,1,1,1,0},//F/15 63 64 {'g',1,0,1,1,1,1,0,0},//G/16 65 {'h',0,1,1,0,1,1,1,0},//H/17 66 67 {'i',0,0,0,0,1,1,0,0},//I/18 68 {'j',0,1,1,1,1,0,0,0},//J/19 69 70 {'l',0,0,0,1,1,1,0,0},//L/20 71 {'n',0,0,1,0,1,0,1,0},//n/21 72 73 {'o',0,0,1,1,1,0,1,0},//o/22 74 {'p',1,1,0,0,1,1,1,0},//P/23 75 76 {'q',1,1,1,0,0,1,1,0},//q/24 77 {'r',0,0,0,0,1,0,1,0},//r/25 78 79 {'s',1,0,1,1,0,1,1,0},//S/26 looks like number 5 80 {'t',0,0,0,1,1,1,1,0},//t/27 81 82 {'u',0,1,1,1,1,1,0,0},//U/28 83 {'y',0,1,1,1,0,1,1,0},//y/29 84 85 {'-',0,0,0,0,0,0,1,0},//-/30 86 {'.',0,0,0,0,0,0,0,1},//./31 87 88 {']',1,1,1,1,0,0,0,0},//]/32 89 {'[',1,0,0,1,1,1,0,0},//[/33 90 91 {'_',0,0,0,1,0,0,0,0},//_/34 92 }; 93 94void setup() { 95 96 // set segment pins as OUTPUT 97pinMode(seg[0],OUTPUT); 98pinMode(seg[1],OUTPUT); 99pinMode(seg[2],OUTPUT); 100pinMode(seg[3],OUTPUT); 101pinMode(seg[4],OUTPUT); 102pinMode(seg[5],OUTPUT); 103pinMode(seg[6],OUTPUT); 104pinMode(seg[7],OUTPUT); 105 106} 107 108 109 110void 111 setState(bool mode) //sets the hole segment state to "mode" 112{ for(int i = 0;i<=6;i++) 113{ 114 115 digitalWrite(seg[i],mode); 116} 117} 118 119 120 121void Print(char Char) // print 122 any character on the segment ( Note : you can't use capital characters ) 123{ 124 125 int charNum = -1;// set search resault to -1 126 setState(segMode);//turn off 127 the segment 128 129for(int i = 0; i < chars ;i++){//search for the enterd character 130 131 if(Char == Chars[i][0]){//if the character found 132 charNum = i;//set the 133 resault number into charNum ( because this function prints the character using it's 134 number in the array ) 135 } 136} 137 138if(charNum == -1 )// if the character 139 not found 140{ 141 for(int i = 0;i <= 6;i++) 142 { 143 digitalWrite(seg[i],HIGH); 144 145 delay(100); 146 digitalWrite(seg[i],LOW); 147 } 148 for(int i = 0;i <= 2;i++) 149{ 150 151 delay(100); 152 setState(HIGH); 153 delay(100); 154 setState(LOW); 155} 156}else 157 // else if the character found print it 158 { 159for(int i = 0;i<8;i++) 160 {digitalWrite(seg[i],Chars[charNum][i+1]); 161 162 } 163 } 164 165} 166 167void Print(int num) // print any number on the segment 168{ 169 170 setState(segMode);//turn off the segment 171 172 173 174if(num > chars 175 || num < 0 )// if the number is not declared 176{ 177 for(int i = 0;i <= 6;i++) 178 179 { 180 digitalWrite(seg[i],HIGH); 181 delay(100); 182 digitalWrite(seg[i],LOW); 183 184 } 185 for(int i = 0;i <= 2;i++) 186{ 187 delay(100); 188 setState(HIGH); 189 190 delay(100); 191 setState(LOW); 192} 193}else // else if the number declared, 194 print it 195 { 196 if(segMode == 0){ //for segment mode 197for(int i = 0;i<8;i++) 198 199 {digitalWrite(seg[i],Chars[num][i+1]); 200 } 201 } 202 else{ 203 for(int 204 i = 0;i<8;i++) 205 {digitalWrite(seg[i],!Chars[num][i+1]); 206 } 207 } 208 209 } 210} 211 212void loop() { 213 214 215 for(int i = 0;i < chars;i++) //print 216 217 { 218 Print(i); 219 delay(1000); 220 } 221 222 223 //Print(number or character); 224 // print any number or character on the segment ( Note : you can't use capital characters 225 ) 226 //setState(state); //sets the hole segment state to "state" 227 228} 229 230 231 232 233
the code:
arduino
1/* 2 Showing numbers, chars and phrases 3 A (seg[0] in this project) 4 --- 5F (seg[5] in this project) | | B (seg[1] in this project) 6 | | 7 --- G (seg[6] in this project) 8E (seg[4] in this project) | | 9 | | C (seg[2] in this project) 10 --- . dot or dicimal (seg[7] in this project) 11 D (seg[3] in this project) 12 13 */ 14#define A 8 15#define B 7 16#define C 6 17#define D 5 18#define E 4 19#define F 3 20#define G 2 21#define DP 9 // decimal 22#define common_cathode 0 23#define common_anode 1 24bool segMode = common_cathode; // set this to your segment type, my segment is common_cathode 25int seg[] {A,B,C,D,E,F,G,DP}; // segment pins 26byte chars = 35; // max value in the array "Chars" 27 28byte Chars[35][9] { 29 {'0',1,1,1,1,1,1,0,0},//0 30 {'1',0,1,1,0,0,0,0,0},//1 31 {'2',1,1,0,1,1,0,1,0},//2 32 {'3',1,1,1,1,0,0,1,0},//3 33 {'4',0,1,1,0,0,1,1,0},//4 34 {'5',1,0,1,1,0,1,1,0},//5 35 {'6',1,0,1,1,1,1,1,0},//6 36 {'7',1,1,1,0,0,0,0,0},//7 37 {'8',1,1,1,1,1,1,1,0},//8 38 {'9',1,1,1,1,0,1,1,0},//9 39 {'a',1,1,1,0,1,1,1,0},//A/10 40 {'b',0,0,1,1,1,1,1,0},//b/11 41 {'c',1,0,0,1,1,1,0,0},//C/12 42 {'d',0,1,1,1,1,0,1,0},//d/13 43 {'e',1,0,0,1,1,1,1,0},//E/14 44 {'f',1,0,0,0,1,1,1,0},//F/15 45 {'g',1,0,1,1,1,1,0,0},//G/16 46 {'h',0,1,1,0,1,1,1,0},//H/17 47 {'i',0,0,0,0,1,1,0,0},//I/18 48 {'j',0,1,1,1,1,0,0,0},//J/19 49 {'l',0,0,0,1,1,1,0,0},//L/20 50 {'n',0,0,1,0,1,0,1,0},//n/21 51 {'o',0,0,1,1,1,0,1,0},//o/22 52 {'p',1,1,0,0,1,1,1,0},//P/23 53 {'q',1,1,1,0,0,1,1,0},//q/24 54 {'r',0,0,0,0,1,0,1,0},//r/25 55 {'s',1,0,1,1,0,1,1,0},//S/26 looks like number 5 56 {'t',0,0,0,1,1,1,1,0},//t/27 57 {'u',0,1,1,1,1,1,0,0},//U/28 58 {'y',0,1,1,1,0,1,1,0},//y/29 59 {'-',0,0,0,0,0,0,1,0},//-/30 60 {'.',0,0,0,0,0,0,0,1},//./31 61 {']',1,1,1,1,0,0,0,0},//]/32 62 {'[',1,0,0,1,1,1,0,0},//[/33 63 {'_',0,0,0,1,0,0,0,0},//_/34 64 }; 65 66void setup() { 67 // set segment pins as OUTPUT 68pinMode(seg[0],OUTPUT); 69pinMode(seg[1],OUTPUT); 70pinMode(seg[2],OUTPUT); 71pinMode(seg[3],OUTPUT); 72pinMode(seg[4],OUTPUT); 73pinMode(seg[5],OUTPUT); 74pinMode(seg[6],OUTPUT); 75pinMode(seg[7],OUTPUT); 76 77} 78 79 80 81void setState(bool mode) //sets the hole segment state to "mode" 82{ for(int i = 0;i<=6;i++) 83{ 84 digitalWrite(seg[i],mode); 85} 86} 87 88 89 90void Print(char Char) // print any character on the segment ( Note : you can't use capital characters ) 91{ 92 int charNum = -1;// set search resault to -1 93 setState(segMode);//turn off the segment 94 95for(int i = 0; i < chars ;i++){//search for the enterd character 96 if(Char == Chars[i][0]){//if the character found 97 charNum = i;//set the resault number into charNum ( because this function prints the character using it's number in the array ) 98 } 99} 100 101if(charNum == -1 )// if the character not found 102{ 103 for(int i = 0;i <= 6;i++) 104 { 105 digitalWrite(seg[i],HIGH); 106 delay(100); 107 digitalWrite(seg[i],LOW); 108 } 109 for(int i = 0;i <= 2;i++) 110{ 111 delay(100); 112 setState(HIGH); 113 delay(100); 114 setState(LOW); 115} 116}else // else if the character found print it 117 { 118for(int i = 0;i<8;i++) 119 {digitalWrite(seg[i],Chars[charNum][i+1]); 120 } 121 } 122 123} 124 125void Print(int num) // print any number on the segment 126{ 127 setState(segMode);//turn off the segment 128 129 130 131if(num > chars || num < 0 )// if the number is not declared 132{ 133 for(int i = 0;i <= 6;i++) 134 { 135 digitalWrite(seg[i],HIGH); 136 delay(100); 137 digitalWrite(seg[i],LOW); 138 } 139 for(int i = 0;i <= 2;i++) 140{ 141 delay(100); 142 setState(HIGH); 143 delay(100); 144 setState(LOW); 145} 146}else // else if the number declared, print it 147 { 148 if(segMode == 0){ //for segment mode 149for(int i = 0;i<8;i++) 150 {digitalWrite(seg[i],Chars[num][i+1]); 151 } 152 } 153 else{ 154 for(int i = 0;i<8;i++) 155 {digitalWrite(seg[i],!Chars[num][i+1]); 156 } 157 } 158 } 159} 160 161void loop() { 162 163 164 for(int i = 0;i < chars;i++) //print 165 { 166 Print(i); 167 delay(1000); 168 } 169 170 171 //Print(number or character); // print any number or character on the segment ( Note : you can't use capital characters ) 172 //setState(state); //sets the hole segment state to "state" 173 174} 175 176 177 178
Downloadable files
circuit:
the resistor is 330 ohm
circuit:
Comments
Only logged in users can leave comments