4 Digit Display Text Scroller (YSD-439AK2B-35)
A 7 segment 4 digit display program that displays and scrolls custom text.
Components and supplies
1
Breadboard - 830 contacts
4
1k Resistor
1
4 Digit 7 Segment Common Anode Display
1
Arduino Uno Rev3
Apps and platforms
1
Arduino IDE 1.8
Project description
Code
Four Digit Scroll
cpp
1/* 2Displays a given string of text and scrolls from right to left. 3Currently, no support for characters: "k, m, w, x". 4Capital letters, symbols, and punctuation are also not supported. 5All unsupported characters will be represented as a space character. 6 7I had some trouble deciphering what each pin's purpose was from the datasheet, 8and so I wanted to include a more straightforward guide below. 9 10 11 16 15 14 13 12 11 10 9 12 ---|--|--|--|--|--|--|--|--- 13 | | 14 | | 15 | | 16 | | 17 ---|--|--|--|--|--|--|--|---- 18 1 2 3 4 5 6 7 8 19 20Pin Functions: 21 22Pin 1: Digit 1 Vin 23Pin 2: Digit 2 Vin 24Pin 3: Segment D Control 25Pin 4: Colon Vin 26Pin 5: Segment E Control 27Pin 6: Digit 3 Vin 28Pin 7: Decimal DP Control 29Pin 8: Digit 4 Vin 30Pin 9: 3rd Digit Upper Right Decimal Control 31Pin 10: 3rd Digit Upper Right Decimal Vin 32Pin 11: Segment F Control 33Pin 12: Colon Control 34Pin 13: Segment C Control 35Pin 14: Segment A Control 36Pin 15: Segment G Control 37Pin 16: Segment B Control 38 39Notes: 40 41-Vin pins need voltage source with some resistance to protect device - I used 5V with 1k resistors 42-Control pins need to be attached to digital output pins on the Arduino 43 44 45----Digit Segment Allocations---- 46 47 A 48 ------- 49 | | 50 F| G |B 51 |-------| 52 E| |C 53 | | 54 ------- 55 D 56 57Notes: 58 59Digit segments are "activated" by setting their corresponding digital output pins to zero 60 61 62----How to use---- 63 64tickRate, scrollSpeed, animationLength, spinSpeed, and message are all variables that can be played with in order to get the right fit 65The pins that I'd used for each segment and digit are displayed below, but feel free to change them depending on your project needs 66 67*/ 68 69//denotes the digital pins used for segment control 70int dig1 = 10; 71int dig2 = 2; 72int dig3 = 12; 73int dig4 = 13; 74 75//denotes the digital pins used for segment control 76int B = 3; 77int G = 4; 78int A = 5; 79int C = 6; 80int F = 7; 81int E = 8; 82int D = 9; 83 84//sets the time (milliseconds) that it takes the microcontroller to switch from one digit to the next 85//(this will be unseen by the human eye unless the value is too high) 86int tickRate = 5; 87 88//SET SCROLL SPEED HERE 89//higher values correspond with slower speed 90int scrollSpeed = 10; 91 92//SET BUFFER ANIMATION LENGTH HERE 93//higher value == longer animation 94int animationLength = 45; 95 96//SET ANIMATION SPEED HERE 97//higher value == slower speed 98int spinSpeed = 4; 99 100//SET DISPLAY MESSAGE HERE 101String message = "test test"; 102 103int mlength = message.length(); 104char window[5]; 105 106void setup() { 107 108 //start the serial monitor 109 Serial.begin(9600); 110 111 //designate the pin modes and turn everything off before starting main loop 112 pinMode(dig1, OUTPUT); 113 pinMode(dig2, OUTPUT); 114 pinMode(dig3, OUTPUT); 115 pinMode(dig4, OUTPUT); 116 117 pinMode(A, OUTPUT); 118 pinMode(B, OUTPUT); 119 pinMode(C, OUTPUT); 120 pinMode(D, OUTPUT); 121 pinMode(E, OUTPUT); 122 pinMode(F, OUTPUT); 123 pinMode(G, OUTPUT); 124 125 digitalWrite(dig1, LOW); 126 digitalWrite(dig2, LOW); 127 digitalWrite(dig3, LOW); 128 digitalWrite(dig4, LOW); 129 130 digitalWrite(A, HIGH); 131 digitalWrite(B, HIGH); 132 digitalWrite(C, HIGH); 133 digitalWrite(D, HIGH); 134 digitalWrite(E, HIGH); 135 digitalWrite(F, HIGH); 136 digitalWrite(G, HIGH); 137} 138 139void loop() { 140 141 //wipes the window clean ready to receive char data 142 window[0] = ' '; 143 window[1] = ' '; 144 window[2] = ' '; 145 window[3] = ' '; 146 147 //loop moves every character in the window over by one 148 //simulates the scrolling effect 149 for (int i=0; i<=(mlength+4); i++){ 150 window[0] = window[1]; 151 window[1] = window[2]; 152 window[2] = window[3]; 153 if (i<mlength) window[3] = message[i]; 154 else window[3] = ' '; 155 156 //prints contents of window into the monitor for debugging 157 Serial.println(window); 158 159 //turns on digits 1-4 one after another 160 //draws a specific character corresponding to the window 161 for (int counter=0; counter<=scrollSpeed; counter++){ 162 low(dig3); 163 draw(window[3]); 164 high(dig4); 165 delay(tickRate); 166 167 low(dig4); 168 draw(window[0]); 169 high(dig1); 170 delay(tickRate); 171 172 low(dig1); 173 draw(window[1]); 174 high(dig2); 175 delay(tickRate); 176 177 low(dig2); 178 draw(window[2]); 179 high(dig3); 180 delay(tickRate); 181 } 182 } 183 184 //a buffer animation added inbetween each cycle 185 for (int i=0; i<=animationLength; i++){ 186 spin(i); 187 for (int k=0; k<=spinSpeed; k++){ 188 low(dig3); high(dig4); 189 delay(tickRate); 190 191 low(dig4); high(dig1); 192 delay(tickRate); 193 194 low(dig1); high(dig2); 195 delay(tickRate); 196 197 low(dig2); high(dig3); 198 delay(tickRate); 199 } 200 } 201} 202 203//this is where the segments are turned on/off depending on the character written in 'message'. 204//'low' designates segment is on while 'high' designates that it's on 205void draw(char a){ 206 switch (a){ 207 case 'a': 208 low(A); low(B); low(C); high(D); low(E); low(F); low(G); 209 break; 210 211 case 'b': 212 high(A); high(B); low(C); low(D); low(E); low(F); low(G); 213 break; 214 215 case 'c': 216 low(A); high(B); high(C); low(D); low(E); low(F); high(G); 217 break; 218 219 case 'd': 220 high(A); low(B); low(C); low(D); low(E); high(F); low(G); 221 break; 222 223 case 'e': 224 low(A); high(B); high(C); low(D); low(E); low(F); low(G); 225 break; 226 227 case 'f': 228 low(A); high(B); high(C); high(D); low(E); low(F); low(G); 229 break; 230 231 case 'g': 232 low(A); high(B); low(C); low(D); low(E); low(F); high(G); 233 break; 234 235 case 'h': 236 high(A); low(B); low(C); high(D); low(E); low(F); low(G); 237 break; 238 239 case 'i': 240 high(A); high(B); high(C); high(D); low(E); low(F); high(G); 241 break; 242 243 case 'j': 244 high(A); low(B); low(C); low(D); low(E); high(F); high(G); 245 break; 246 247 case 'l': 248 high(A); high(B); high(C); low(D); low(E); low(F); high(G); 249 break; 250 251 case 'n': 252 high(A); high(B); low(C); high(D); low(E); high(F); low(G); 253 break; 254 255 case 'o': 256 high(A); high(B); low(C); low(D); low(E); high(F); low(G); 257 break; 258 259 case 'p': 260 low(A); low(B); high(C); high(D); low(E); low(F); low(G); 261 break; 262 263 case 'q': 264 low(A); low(B); low(C); high(D); high(E); low(F); low(G); 265 break; 266 267 case 'r': 268 high(A); high(B); high(C); high(D); low(E); high(F); low(G); 269 break; 270 271 case 's': 272 low(A); high(B); low(C); low(D); high(E); low(F); low(G); 273 break; 274 275 case 't': 276 high(A); high(B); high(C); low(D); low(E); low(F); low(G); 277 break; 278 279 case 'u': 280 high(A); high(B); low(C); low(D); low(E); high(F); high(G); 281 break; 282 283 case 'v': 284 high(A); high(B); low(C); low(D); low(E); high(F); high(G); 285 break; 286 287 case 'y': 288 high(A); low(B); low(C); high(D); high(E); low(F); low(G); 289 break; 290 291 case 'z': 292 low(A); low(B); high(C); low(D); low(E); high(F); low(G); 293 break; 294 295 case '1': 296 high(A); high(B); high(C); high(D); low(E); low(F); high(G); 297 break; 298 299 case '2': 300 low(A); low(B); high(C); low(D); low(E); high(F); low(G); 301 break; 302 303 case '3': 304 low(A); low(B); low(C); low(D); high(E); high(F); low(G); 305 break; 306 307 case '4': 308 high(A); low(B); low(C); high(D); high(E); low(F); low(G); 309 break; 310 311 case '5': 312 low(A); high(B); low(C); low(D); high(E); low(F); low(G); 313 break; 314 315 case '6': 316 low(A); high(B); low(C); low(D); low(E); low(F); low(G); 317 break; 318 319 case '7': 320 low(A); low(B); low(C); high(D); high(E); high(F); high(G); 321 break; 322 323 case '8': 324 low(A); low(B); low(C); low(D); low(E); low(F); low(G); 325 break; 326 327 case '9': 328 low(A); low(B); low(C); high(D); high(E); low(F); low(G); 329 break; 330 331 default: 332 high(A); high(B); high(C); high(D); high(E); high(F); high(G); 333 break; 334 } 335} 336 337//denotes the segments drawn for the buffer animation 338void spin(int a){ 339 while (a >= 6) a = a - 6; 340 switch (a){ 341 case 0: 342 low(A); high(B); high(C); high(D); high(E); high(F); high(G); 343 break; 344 345 case 1: 346 high(A); low(B); high(C); high(D); high(E); high(F); high(G); 347 break; 348 349 case 2: 350 high(A); high(B); low(C); high(D); high(E); high(F); high(G); 351 break; 352 353 case 3: 354 high(A); high(B); high(C); low(D); high(E); high(F); high(G); 355 break; 356 357 case 4: 358 high(A); high(B); high(C); high(D); low(E); high(F); high(G); 359 break; 360 361 case 5: 362 high(A); high(B); high(C); high(D); high(E); low(F); high(G); 363 break; 364 } 365} 366 367//these are shorthand functions that I wrote so I wouldn't have to type digitalWrite over and over. 368void low(int a){ 369 digitalWrite(a, LOW); 370} 371 372void high(int a){ 373 digitalWrite(a, HIGH); 374}
Comments
Only logged in users can leave comments