Components and supplies
Arduino Mega 2560
Standard LCD - 16x2 White on Blue
Pushbutton switch 12mm
Shift Register- Serial to Parallel
LED (generic)
Rotary potentiometer (generic)
Resistor 221 ohm
Apps and platforms
Arduino IDE
Project description
Code
8_X_8_LEDS_matrix_with_2_X_74HC595.ino
c_cpp
This is the full program. All you need is the render() method in order to render the leds, others are just for programs and modes.
1/* 8 X 8 LED Matrix Using 2 x 47HC595 Shift Registers 2 3 A simple Arduino project, allows to control 8 x 8 leds matrix using only 2 shift registers. 4 04.10.2018 by Alaa Ibrahim Hadid 5 Copyright Alaa Ibrahim Hadid 2018 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19*/ 20// Started 23.10.2018 21// Finished 26.10.2018 22 23// Update 19.01.2019 24// ................. 25// * Updated the shift out method to use SPI 26// * Changed the pins and connections of the shift registers. 27// Now it works like this: 28// - VCCs shift register latch pin is connected to PWM 2 (pin 2) 29// - GNDs shift register latch pin is connected to PWM 3 (pin 3) 30// - Data pins of both shift registers are connected to pin 51 (digital pin) 31// - Clock pins of both shift registers are connected to pin 52 (digital pin) 32// * Changed the degitalWrite into using direct PORT access instead 33// The result is even faster shifting and leds control. 34 35// LiquidCrystal library is needed for the display. 36#include <SPI.h> 37#include <LiquidCrystal.h> 38 39#define CLR(x,y) (x&=(~(1<<y))) 40#define SET(x,y) (x|=(1<<y)) 41 42// LCD 43LiquidCrystal lcd(8, 9, 10, 11, 12, 13); 44char* program_name; 45bool lcd_update_required = false; 46 47// PINS (port numbers) 48// WARNING !! 49// You may want to change these numbers to suit your Arduino board, this code written for ATmega2560. See https://www.arduino.cc/en/Hacking/PinMapping2560 50int pe_vccs_latch = 4;// PE4 on ATmega2560 is PWM 2, so bisacly we are telling Arduino to use pin 2, which is connected to VCCs shift register latch 51int pe_gnds_latch = 5;// PE5 on ATmega2560 is PWM 3, so bisacly we are telling Arduino to use pin 3, which is connected to GNDs shift register latch 52// Data pins of both shift registers are connected to pin 51 (digital pin) 53// Clock pins of both shift registers are connected to pin 52 (digital pin) 54 55// The leds matrix that will be shown 56unsigned char LEDS [] = 57{ 58 0x00, 59 0x00, 60 0x00, 61 0x0, 62 0x0, 63 0x0, 64 0x0, 65 0 66}; 67bool lcd_direction_mode = false; // The direction, false= left bottom to right up, true= right bottom to left up 68bool leds_on = true; 69// We need these for program updates 70int counter = 0; 71int i = 0; 72int scroll_speed = 11; 73int program_index = 0; 74// Inputs program 75int input_mode = 0; 76int input_counter = 0; 77int input_sensivity = 30; 78 79// Program - Scan 80int p_s_index = 0; 81// Program - Wave 82int p_w_col0 = 0; 83// Program - River 84int p_r_i = 0; 85// Program - Cycle 86int p_c_counter = 0; 87int p_c_timer = 70; 88int p_c_program_index = 0; 89// Program - Alphabet 90int p_a_counter = 0; 91int p_a_char_index = 0; 92int p_a_wait = 15; 93// Program - Circle 94int p_c_index = 0; 95bool p_c_flp; 96 97void setup() { 98 //PORTE on Arduino MEGA 2560 is for PWM 0 to 7, you may need to change the direction port on this code. 99 // Here, we are setting all PWM pins we need to OUTPUT. 100 SET(DDRE, pe_vccs_latch); 101 SET(DDRE, pe_gnds_latch); 102 103 // Setup button pins 104 pinMode(A0, INPUT_PULLUP); 105 pinMode(A1, INPUT_PULLUP); 106 pinMode(A2, INPUT_PULLUP); 107 pinMode(A3, INPUT_PULLUP); 108 109 // Setup SPI. Currently, i connect the pin 51 as Data and 52 as Clock for the shift registers. 110 SPI.begin(); 111 SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV2, MSBFIRST, SPI_MODE0)); 112 113 // Setup values 114 leds_on = true; 115 program_index = 22; 116 program_name = "Random Prog"; 117 118 // set up the LCD's number of columns and rows: 119 lcd.begin(16, 2); 120 // Print a message to the LCD. 121 lcd.print("WELCOME !!"); 122 lcd_update_required = true; 123} 124 125// Rendering methods 126void Render() 127{ 128 if (!leds_on) 129 return; 130 if (!lcd_direction_mode) 131 { 132 // 1st row 133 PutRowGND(0xFE); 134 for (int col = 0; col < 8; col ++) 135 { 136 int reg = 1 << col; 137 PutColumnVCC((unsigned char)(LEDS[0] & reg)); 138 } 139 PutColumnVCC(0); 140 // 2nd row 141 PutRowGND(0xFD); 142 for (int col = 0; col < 8; col ++) 143 { 144 int reg = 1 << col; 145 PutColumnVCC((unsigned char)(LEDS[1] & reg)); 146 } 147 PutColumnVCC(0); 148 // 3rd row 149 PutRowGND(0xFB); 150 for (int col = 0; col < 8; col ++) 151 { 152 int reg = 1 << col; 153 PutColumnVCC((unsigned char)(LEDS[2] & reg)); 154 } 155 PutColumnVCC(0); 156 // 4th row 157 PutRowGND(0xF7); 158 for (int col = 0; col < 8; col ++) 159 { 160 int reg = 1 << col; 161 PutColumnVCC((unsigned char)(LEDS[3] & reg)); 162 } 163 PutColumnVCC(0); 164 // 5th row 165 PutRowGND(0xEF); 166 for (int col = 0; col < 8; col ++) 167 { 168 int reg = 1 << col; 169 PutColumnVCC((unsigned char)(LEDS[4] & reg)); 170 } 171 PutColumnVCC(0); 172 // 6th row 173 PutRowGND(0xDF); 174 for (int col = 0; col < 8; col ++) 175 { 176 int reg = 1 << col; 177 PutColumnVCC((unsigned char)(LEDS[5] & reg)); 178 } 179 PutColumnVCC(0); 180 // 7th row 181 PutRowGND(0xBF); 182 for (int col = 0; col < 8; col ++) 183 { 184 int reg = 1 << col; 185 PutColumnVCC((unsigned char)(LEDS[6] & reg)); 186 } 187 PutColumnVCC(0); 188 // 8th row 189 PutRowGND(0x7F); 190 for (int col = 0; col < 8; col ++) 191 { 192 int reg = 1 << col; 193 PutColumnVCC((unsigned char)(LEDS[7] & reg)); 194 } 195 PutColumnVCC(0); 196 } 197 else // Render method 2. Optional 198 { 199 // 8th row 200 PutRowGND(0x7F); 201 for (int col = 0; col < 8; col ++) 202 { 203 int reg = 0x80 >> col; 204 PutColumnVCC(LEDS[0] & reg); 205 } 206 PutColumnVCC(0); 207 // 7th row 208 PutRowGND(0xBF); 209 for (int col = 0; col < 8; col ++) 210 { 211 int reg = 0x80 >> col; 212 PutColumnVCC(LEDS[1] & reg); 213 } 214 PutColumnVCC(0); 215 // 6th row 216 PutRowGND(0xDF); 217 for (int col = 0; col < 8; col ++) 218 { 219 int reg = 0x80 >> col; 220 PutColumnVCC(LEDS[2] & reg); 221 } 222 PutColumnVCC(0); 223 // 5th row 224 PutRowGND(0xEF); 225 for (int col = 0; col < 8; col ++) 226 { 227 int reg = 0x80 >> col; 228 PutColumnVCC(LEDS[3] & reg); 229 } 230 PutColumnVCC(0); 231 // 4th row 232 PutRowGND(0xF7); 233 for (int col = 0; col < 8; col ++) 234 { 235 int reg = 0x80 >> col; 236 PutColumnVCC(LEDS[4] & reg); 237 } 238 PutColumnVCC(0); 239 // 3rd row 240 PutRowGND(0xFB); 241 for (int col = 0; col < 8; col ++) 242 { 243 int reg = 0x80 >> col; 244 PutColumnVCC(LEDS[5] & reg); 245 } 246 PutColumnVCC(0); 247 // 2nd row 248 PutRowGND(0xFD); 249 for (int col = 0; col < 8; col ++) 250 { 251 int reg = 0x80 >> col; 252 PutColumnVCC(LEDS[6] & reg); 253 } 254 PutColumnVCC(0); 255 // 1st row 256 PutRowGND(0xFE); 257 for (int col = 0; col < 8; col ++) 258 { 259 int reg = 1 << col; 260 if (lcd_direction_mode) 261 reg = 0x80 >> col; 262 PutColumnVCC(LEDS[7] & reg); 263 } 264 PutColumnVCC(0); 265 } 266} 267void UpdateLCD() 268{ 269 if (!lcd_update_required) 270 return; 271 272 if (!leds_on) 273 { 274 lcd.setCursor(0, 0); 275 lcd.print("LEDS OFF "); 276 lcd.print(" "); 277 lcd.setCursor(0, 1); 278 lcd.print("PRESS ON BUTTON "); 279 return; 280 281 } 282 // See what mode we are at 283 switch (input_mode) 284 { 285 case 0: // Programs switching 286 { 287 lcd.setCursor(0, 0); 288 lcd.print("PAGE1: PRORGRAM "); 289 lcd.setCursor(0, 1); 290 lcd.print(""); 291 lcd.print(program_index + 1); 292 lcd.print(" "); 293 lcd.print(program_name); 294 lcd.print(" "); 295 break; 296 } 297 case 1: // SPEED SET 298 { 299 lcd.setCursor(0, 0); 300 lcd.print("PAGE2: SPEED SET"); 301 lcd.setCursor(0, 1); 302 lcd.print("Update Speed: "); 303 lcd.print(scroll_speed); 304 lcd.print(" "); 305 break; 306 } 307 case 2: // LEDS DIRECT 308 { 309 lcd.setCursor(0, 0); 310 lcd.print("PAGE3: DIRECTION"); 311 lcd.setCursor(0, 1); 312 if (lcd_direction_mode) 313 { 314 lcd.print("REVERSE"); 315 } 316 else 317 { 318 lcd.print("NORMAL"); 319 } 320 321 lcd.print(" "); 322 break; 323 } 324 } 325 lcd_update_required = false; 326} 327void UpdateProgram() 328{ 329 if (!leds_on) 330 return; 331 counter ++; 332 if (counter >= scroll_speed) 333 { 334 counter = 0; 335 ChooseProgram(program_index); 336 } 337} 338void HandleInputs() 339{ 340 if (input_counter > 0) 341 { 342 input_counter--; 343 return; 344 } 345 346 // ON / OFF 347 if (digitalRead(A3) == LOW) 348 { 349 leds_on = !leds_on; 350 input_counter = input_sensivity; 351 352 SetProgramName(); 353 lcd_update_required = true; 354 355 if (!leds_on) 356 { 357 PutColumnVCC(0); 358 PutRowGND(0); 359 } 360 } 361 362 // Page select 363 if (digitalRead(A2) == LOW) 364 { 365 input_mode++; 366 if (input_mode > 2) 367 { 368 input_mode = 0; 369 } 370 input_counter = input_sensivity; 371 372 SetProgramName(); 373 lcd_update_required = true; 374 } 375 // See what mode we are at 376 switch (input_mode) 377 { 378 case 0: // Prorams switching 379 { 380 if (digitalRead(A0) == LOW) 381 { 382 input_counter = input_sensivity; 383 // Previous program 384 program_index--; 385 if (program_index < 0) 386 program_index = 22; 387 SetProgramName(); 388 lcd_update_required = true; 389 } 390 else if (digitalRead(A1) == LOW) 391 { 392 input_counter = input_sensivity; 393 // Next program 394 program_index++; 395 if (program_index > 22) 396 program_index = 0; 397 SetProgramName(); 398 lcd_update_required = true; 399 } 400 break; 401 } 402 case 1: // Speed Set 403 { 404 if (digitalRead(A0) == LOW) 405 { 406 input_counter = input_sensivity; 407 408 scroll_speed--; 409 if (scroll_speed < 1) 410 scroll_speed = 25; 411 412 lcd_update_required = true; 413 } 414 else if (digitalRead(A1) == LOW) 415 { 416 input_counter = input_sensivity; 417 // Next program 418 scroll_speed++; 419 if (scroll_speed > 25) 420 scroll_speed = 1; 421 422 lcd_update_required = true; 423 } 424 break; 425 } 426 case 2: // LEDS mode select 427 { 428 if (digitalRead(A0) == LOW || digitalRead(A1) == LOW) 429 { 430 input_counter = input_sensivity; 431 432 lcd_direction_mode = !lcd_direction_mode; 433 lcd_update_required = true; 434 } 435 break; 436 } 437 } 438} 439void SetProgramName() 440{ 441 switch (program_index) 442 { 443 case 0: program_name = "Scan"; break; 444 case 1: program_name = "Fill"; break; 445 case 2: program_name = "All"; break; 446 case 3: program_name = "Bars"; break; 447 case 4: program_name = "Wave 1"; break; 448 case 5: program_name = "Wave 2"; break; 449 case 6: program_name = "Fill"; break; 450 case 7: program_name = "Random"; break; 451 case 8: program_name = "River"; break; 452 case 9: program_name = "Yellows"; break; 453 case 10: program_name = "Greens"; break; 454 case 11: program_name = "Reds"; break; 455 case 12: program_name = "Alphabet"; break; 456 case 13: program_name = "Numbers"; break; 457 case 14: program_name = "Love You"; break; 458 case 15: program_name = "Circle"; break; 459 case 16: program_name = "Tunnle"; break; 460 461 case 17: program_name = "Heart 1"; break; 462 case 18: program_name = "Heart 2"; break; 463 case 19: program_name = "Heart 3"; break; 464 case 20: program_name = "Heart 4"; break; 465 466 case 21: program_name = "Cycle Programs"; break; 467 case 22: program_name = "Random Prog"; break; 468 } 469} 470void ChooseProgram(int index) 471{ 472 switch (index) 473 { 474 case 0: UpdateProgram_SCAN(); program_name = "Scan"; break; 475 case 1: UpdateProgram_Count(); program_name = "Fill"; break; 476 case 2: UpdateProgram_Full(); program_name = "All"; break; 477 case 3: UpdateProgram_Analiser(); program_name = "Bars"; break; 478 case 4: UpdateProgram_Wave(); program_name = "Wave 1"; break; 479 case 5: UpdateProgram_MiddWave(); program_name = "Wave 2"; break; 480 case 6: UpdateProgram_FILL(); program_name = "Fill"; break; 481 case 7: UpdateProgram_Random(); program_name = "Random"; break; 482 case 8: UpdateProgram_River(); program_name = "River"; break; 483 case 9: UpdateProgram_Yellows(); program_name = "Yellows"; break; 484 case 10: UpdateProgram_Greens(); program_name = "Greens"; break; 485 case 11: UpdateProgram_Reds(); program_name = "Reds"; break; 486 case 12: UpdateProgram_AlphaBet(); program_name = "Alphabet"; break; 487 case 13: UpdateProgram_CountNumbers(); program_name = "Numbers"; break; 488 case 14: UpdateProgram_ILoveYou(); program_name = "Love You"; break; 489 case 15: UpdateProgram_Circle(); program_name = "Circle"; break; 490 case 16: UpdateProgram_Tunnle(); program_name = "Tunnle"; break; 491 492 case 17: UpdateProgram_Heart1(); program_name = "Heart 1"; break; 493 case 18: UpdateProgram_Heart2(); program_name = "Heart 2"; break; 494 case 19: UpdateProgram_Heart3(); program_name = "Heart 3"; break; 495 case 20: UpdateProgram_Heart4(); program_name = "Heart 4"; break; 496 497 case 21: UpdateProgram_CyclePrograms(); program_name = "Cycle Programs"; break; 498 case 22: UpdateProgram_CycleProgramsRandom(); program_name = "Random Prog"; break; 499 } 500} 501// These methods are required to shift values into the shift registers 502void PutColumnVCC(unsigned char col) 503{ 504 CLR(PORTE, pe_vccs_latch);// Clear PWM pin 2 (PE4) 505 506 SPI.transfer(col); 507 508 SET(PORTE, pe_vccs_latch);// Set PWM pin 2 (PE4) 509} 510void PutRowGND(unsigned char row) 511{ 512 CLR(PORTE, pe_gnds_latch);// Clear PWM pin 3 (PE5) 513 514 SPI.transfer(row); 515 516 SET(PORTE, pe_gnds_latch);// Set PWM pin 3 (PE5) 517} 518// Optional methods, plays around with leds. 519void SetChar(char* c) 520{ 521 // The scaning process starts from row 0 to row 7. Since the leds are aranged from bottom to top, we need to setup them from top to bottom. 522 523 if (c == "-") 524 { 525 LEDS [7] = B00000000; 526 LEDS [6] = B00000000; 527 LEDS [5] = B00000000; 528 LEDS [4] = B01111110; 529 LEDS [3] = B01111110; 530 LEDS [2] = B00000000; 531 LEDS [1] = B00000000; 532 LEDS [0] = B00000000; 533 } 534 else if (c == "heart") 535 { 536 LEDS [7] = B00000000; 537 LEDS [6] = B11100111; 538 LEDS [5] = B10011001; 539 LEDS [4] = B10000001; 540 LEDS [3] = B10000001; 541 LEDS [2] = B01000010; 542 LEDS [1] = B00100100; 543 LEDS [0] = B00011000; 544 } 545 else if (c == "heartfull") 546 { 547 LEDS [7] = B00000000; 548 LEDS [6] = B11100111; 549 LEDS [5] = B11111111; 550 LEDS [4] = B11111111; 551 LEDS [3] = B11111111; 552 LEDS [2] = B01111110; 553 LEDS [1] = B00111100; 554 LEDS [0] = B00011000; 555 } 556 else if (c == "1") 557 { 558 LEDS [7] = B00000000; 559 LEDS [6] = B00001110; 560 LEDS [5] = B00010110; 561 LEDS [4] = B00100110; 562 LEDS [3] = B01000110; 563 LEDS [2] = B00000110; 564 LEDS [1] = B00000110; 565 LEDS [0] = B00000000; 566 } 567 else if (c == "2") 568 { 569 LEDS [7] = B00000000; 570 LEDS [6] = B01111110; 571 LEDS [5] = B00000010; 572 LEDS [4] = B01111110; 573 LEDS [3] = B01111110; 574 LEDS [2] = B01000000; 575 LEDS [1] = B01111110; 576 LEDS [0] = B00000000; 577 } 578 else if (c == "3") 579 { 580 LEDS [7] = B00000000; 581 LEDS [6] = B01111110; 582 LEDS [5] = B00000010; 583 LEDS [4] = B01111110; 584 LEDS [3] = B01111110; 585 LEDS [2] = B00000010; 586 LEDS [1] = B01111110; 587 LEDS [0] = B00000000; 588 } 589 else if (c == "4") 590 { 591 LEDS [7] = B00000000; 592 LEDS [6] = B01000010; 593 LEDS [5] = B01000010; 594 LEDS [4] = B01111110; 595 LEDS [3] = B01111110; 596 LEDS [2] = B00000010; 597 LEDS [1] = B00000010; 598 LEDS [0] = B00000000; 599 } 600 else if (c == "5") 601 { 602 LEDS [7] = B00000000; 603 LEDS [6] = B01111110; 604 LEDS [5] = B01000000; 605 LEDS [4] = B01111110; 606 LEDS [3] = B01111110; 607 LEDS [2] = B00000010; 608 LEDS [1] = B01111110; 609 LEDS [0] = B00000000; 610 } 611 else if (c == "6") 612 { 613 LEDS [7] = B00000000; 614 LEDS [6] = B01111110; 615 LEDS [5] = B01000000; 616 LEDS [4] = B01111110; 617 LEDS [3] = B01111110; 618 LEDS [2] = B01000010; 619 LEDS [1] = B01111110; 620 LEDS [0] = B00000000; 621 } 622 else if (c == "7") 623 { 624 LEDS [7] = B00000000; 625 LEDS [6] = B01111110; 626 LEDS [5] = B00000110; 627 LEDS [4] = B00001100; 628 LEDS [3] = B00011000; 629 LEDS [2] = B00110000; 630 LEDS [1] = B01100000; 631 LEDS [0] = B00000000; 632 } 633 else if (c == "8") 634 { 635 LEDS [7] = B00000000; 636 LEDS [6] = B00111100; 637 LEDS [5] = B01000010; 638 LEDS [4] = B00111100; 639 LEDS [3] = B00111100; 640 LEDS [2] = B01000010; 641 LEDS [1] = B00111100; 642 LEDS [0] = B00000000; 643 } 644 else if (c == "9") 645 { 646 LEDS [7] = B00000000; 647 LEDS [6] = B01111110; 648 LEDS [5] = B01000010; 649 LEDS [4] = B01111110; 650 LEDS [3] = B01111110; 651 LEDS [2] = B00000010; 652 LEDS [1] = B01111110; 653 LEDS [0] = B00000000; 654 } 655 else if (c == "0") 656 { 657 LEDS [7] = B00000000; 658 LEDS [6] = B00111100; 659 LEDS [5] = B01000110; 660 LEDS [4] = B01001010; 661 LEDS [3] = B01010010; 662 LEDS [2] = B01100010; 663 LEDS [1] = B00111100; 664 LEDS [0] = B00000000; 665 } 666 else if (c == "a" || c == "A") 667 { 668 LEDS [7] = B00000000; 669 LEDS [6] = B01111110; 670 LEDS [5] = B01000010; 671 LEDS [4] = B01111110; 672 LEDS [3] = B01000010; 673 LEDS [2] = B01000010; 674 LEDS [1] = B01000010; 675 LEDS [0] = B00000000; 676 } 677 else if (c == "b" || c == "B") 678 { 679 LEDS [7] = B00000000; 680 LEDS [6] = B01111100; 681 LEDS [5] = B01000010; 682 LEDS [4] = B01111100; 683 LEDS [3] = B01000010; 684 LEDS [2] = B01000010; 685 LEDS [1] = B01111100; 686 LEDS [0] = B00000000; 687 } 688 else if (c == "c" || c == "C") 689 { 690 LEDS [7] = B00000000; 691 LEDS [6] = B01111110; 692 LEDS [5] = B01000000; 693 LEDS [4] = B01000000; 694 LEDS [3] = B01000000; 695 LEDS [2] = B01000000; 696 LEDS [1] = B01111110; 697 LEDS [0] = B00000000; 698 } 699 else if (c == "d" || c == "D") 700 { 701 LEDS [7] = B00000000; 702 LEDS [6] = B01111100; 703 LEDS [5] = B01000010; 704 LEDS [4] = B01000010; 705 LEDS [3] = B01000010; 706 LEDS [2] = B01000010; 707 LEDS [1] = B01111100; 708 LEDS [0] = B00000000; 709 } 710 else if (c == "e" || c == "E") 711 { 712 LEDS [7] = B00000000; 713 LEDS [6] = B01111110; 714 LEDS [5] = B01000000; 715 LEDS [4] = B01111110; 716 LEDS [3] = B01111110; 717 LEDS [2] = B01000000; 718 LEDS [1] = B01111110; 719 LEDS [0] = B00000000; 720 } 721 else if (c == "f" || c == "F") 722 { 723 LEDS [7] = B00000000; 724 LEDS [6] = B01111110; 725 LEDS [5] = B01000000; 726 LEDS [4] = B01111110; 727 LEDS [3] = B01111110; 728 LEDS [2] = B01000000; 729 LEDS [1] = B01000000; 730 LEDS [0] = B00000000; 731 } 732 else if (c == "g" || c == "G") 733 { 734 LEDS [7] = B00000000; 735 LEDS [6] = B01111110; 736 LEDS [5] = B01000000; 737 LEDS [4] = B01011110; 738 LEDS [3] = B01010010; 739 LEDS [2] = B01000010; 740 LEDS [1] = B01111110; 741 LEDS [0] = B00000000; 742 } 743 else if (c == "h" || c == "H") 744 { 745 LEDS [7] = B00000000; 746 LEDS [6] = B01000010; 747 LEDS [5] = B01000010; 748 LEDS [4] = B01111110; 749 LEDS [3] = B01000010; 750 LEDS [2] = B01000010; 751 LEDS [1] = B01000010; 752 LEDS [0] = B00000000; 753 } 754 else if (c == "i" || c == "I") 755 { 756 LEDS [7] = B00000000; 757 LEDS [6] = B00111100; 758 LEDS [5] = B00011000; 759 LEDS [4] = B00011000; 760 LEDS [3] = B00011000; 761 LEDS [2] = B00011000; 762 LEDS [1] = B00111100; 763 LEDS [0] = B00000000; 764 } 765 else if (c == "j" || c == "J") 766 { 767 LEDS [7] = B00000000; 768 LEDS [6] = B00011110; 769 LEDS [5] = B00001100; 770 LEDS [4] = B00001100; 771 LEDS [3] = B00001100; 772 LEDS [2] = B00101100; 773 LEDS [1] = B00111100; 774 LEDS [0] = B00000000; 775 } 776 else if (c == "k" || c == "K") 777 { 778 LEDS [7] = B00000000; 779 LEDS [6] = B01001000; 780 LEDS [5] = B01010000; 781 LEDS [4] = B01100000; 782 LEDS [3] = B01100000; 783 LEDS [2] = B01011000; 784 LEDS [1] = B01000100; 785 LEDS [0] = B00000000; 786 } 787 else if (c == "l" || c == "L") 788 { 789 LEDS [7] = B00000000; 790 LEDS [6] = B01000000; 791 LEDS [5] = B01000000; 792 LEDS [4] = B01000000; 793 LEDS [3] = B01000000; 794 LEDS [2] = B01000000; 795 LEDS [1] = B01111110; 796 LEDS [0] = B00000000; 797 } 798 else if (c == "m" || c == "M") 799 { 800 LEDS [7] = B00000000; 801 LEDS [6] = B01111110; 802 LEDS [5] = B01011010; 803 LEDS [4] = B01011010; 804 LEDS [3] = B01011010; 805 LEDS [2] = B01011010; 806 LEDS [1] = B01011010; 807 LEDS [0] = B00000000; 808 } 809 else if (c == "n" || c == "N") 810 { 811 LEDS [7] = B00000000; 812 LEDS [6] = B01000010; 813 LEDS [5] = B01100010; 814 LEDS [4] = B01010010; 815 LEDS [3] = B01001010; 816 LEDS [2] = B01000110; 817 LEDS [1] = B01000010; 818 LEDS [0] = B00000000; 819 } 820 else if (c == "o" || c == "O") 821 { 822 LEDS [7] = B00000000; 823 LEDS [6] = B00111100; 824 LEDS [5] = B01000010; 825 LEDS [4] = B01000010; 826 LEDS [3] = B01000010; 827 LEDS [2] = B01000010; 828 LEDS [1] = B00111100; 829 LEDS [0] = B00000000; 830 } 831 else if (c == "p" || c == "P") 832 { 833 LEDS [7] = B00000000; 834 LEDS [6] = B01111110; 835 LEDS [5] = B01000010; 836 LEDS [4] = B01111110; 837 LEDS [3] = B01111110; 838 LEDS [2] = B01000000; 839 LEDS [1] = B01000000; 840 LEDS [0] = B00000000; 841 } 842 else if (c == "q" || c == "Q") 843 { 844 LEDS [7] = B00000000; 845 LEDS [6] = B01111110; 846 LEDS [5] = B01000010; 847 LEDS [4] = B01000010; 848 LEDS [3] = B01001010; 849 LEDS [2] = B01000110; 850 LEDS [1] = B01111110; 851 LEDS [0] = B00000001; 852 } 853 else if (c == "r" || c == "R") 854 { 855 LEDS [7] = B00000000; 856 LEDS [6] = B01111110; 857 LEDS [5] = B01000010; 858 LEDS [4] = B01111110; 859 LEDS [3] = B01010000; 860 LEDS [2] = B01001000; 861 LEDS [1] = B01000100; 862 LEDS [0] = B00000000; 863 } 864 else if (c == "s" || c == "S") 865 { 866 LEDS [7] = B00000000; 867 LEDS [6] = B01111110; 868 LEDS [5] = B01000000; 869 LEDS [4] = B01111110; 870 LEDS [3] = B00000010; 871 LEDS [2] = B00000010; 872 LEDS [1] = B01111110; 873 LEDS [0] = B00000000; 874 } 875 else if (c == "t" || c == "T") 876 { 877 LEDS [7] = B00000000; 878 LEDS [6] = B01111110; 879 LEDS [5] = B00011000; 880 LEDS [4] = B00011000; 881 LEDS [3] = B00011000; 882 LEDS [2] = B00011000; 883 LEDS [1] = B00011000; 884 LEDS [0] = B00000000; 885 } 886 else if (c == "u" || c == "U") 887 { 888 LEDS [7] = B00000000; 889 LEDS [6] = B01000010; 890 LEDS [5] = B01000010; 891 LEDS [4] = B01000010; 892 LEDS [3] = B01000010; 893 LEDS [2] = B01000010; 894 LEDS [1] = B00111100; 895 LEDS [0] = B00000000; 896 } 897 else if (c == "v" || c == "V") 898 { 899 LEDS [7] = B00000000; 900 LEDS [6] = B01000010; 901 LEDS [5] = B01000010; 902 LEDS [4] = B01000010; 903 LEDS [3] = B01000010; 904 LEDS [2] = B00100100; 905 LEDS [1] = B00011000; 906 LEDS [0] = B00000000; 907 } 908 else if (c == "w" || c == "W") 909 { 910 LEDS [7] = B00000000; 911 LEDS [6] = B01011010; 912 LEDS [5] = B01011010; 913 LEDS [4] = B01011010; 914 LEDS [3] = B01011010; 915 LEDS [2] = B01011010; 916 LEDS [1] = B01111110; 917 LEDS [0] = B00000000; 918 } 919 else if (c == "x" || c == "X") 920 { 921 LEDS [7] = B00000000; 922 LEDS [6] = B01000010; 923 LEDS [5] = B00100100; 924 LEDS [4] = B00011000; 925 LEDS [3] = B00100100; 926 LEDS [2] = B01000010; 927 LEDS [1] = B00000000; 928 LEDS [0] = B00000000; 929 } 930 else if (c == "y" || c == "Y") 931 { 932 LEDS [7] = B00000000; 933 LEDS [6] = B01000010; 934 LEDS [5] = B00100100; 935 LEDS [4] = B00011000; 936 LEDS [3] = B00011000; 937 LEDS [2] = B00011000; 938 LEDS [1] = B00011000; 939 LEDS [0] = B00000000; 940 } 941 else if (c == "z" || c == "Z") 942 { 943 LEDS [7] = B00000000; 944 LEDS [6] = B01111110; 945 LEDS [5] = B00000100; 946 LEDS [4] = B00001000; 947 LEDS [3] = B00010000; 948 LEDS [2] = B00100000; 949 LEDS [1] = B01111110; 950 LEDS [0] = B00000000; 951 } 952 953 for (int i = 0; i < 8; i ++) 954 { 955 byte reg = (LEDS[i] & 0x80) >> 7; 956 reg |= (LEDS[i] & 0x40) >> 5; 957 reg |= (LEDS[i] & 0x20) >> 3; 958 reg |= (LEDS[i] & 0x10) >> 1; 959 reg |= (LEDS[i] & 0x08) << 1; 960 reg |= (LEDS[i] & 0x04) << 3; 961 reg |= (LEDS[i] & 0x02) << 5; 962 reg |= (LEDS[i] & 0x01) << 7; 963 964 LEDS[i] = reg; 965 } 966} 967 968// Programs 969void UpdateProgram_Count() 970{ 971 p_s_index++; 972 if (p_s_index >= 64) 973 { 974 p_s_index = 0; 975 976 LEDS[0] = 0; 977 LEDS[1] = 0; 978 LEDS[2] = 0; 979 LEDS[3] = 0; 980 LEDS[4] = 0; 981 LEDS[5] = 0; 982 LEDS[6] = 0; 983 LEDS[7] = 0; 984 } 985 986 int row = p_s_index / 8; 987 int col = p_s_index % 8; 988 989 byte reg = 0; 990 991 for (int i = 0; i <= col; i++) 992 { 993 reg |= 0x01 << i; 994 } 995 LEDS[row] = reg; 996} 997void UpdateProgram_Full() 998{ 999 for (int i = 0; i < 8; i++) 1000 { 1001 LEDS[i] = 0xFF; 1002 } 1003} 1004void UpdateProgram_SCAN() 1005{ 1006 p_s_index++; 1007 if (p_s_index >= 64) 1008 { 1009 p_s_index = 0; 1010 } 1011 1012 int row = p_s_index / 8; 1013 int col = p_s_index % 8; 1014 1015 LEDS[row] = (unsigned char)(1 << col); 1016 if (row > 0) 1017 LEDS[row - 1] = 0; 1018 else 1019 LEDS[7] = 0; 1020} 1021void UpdateProgram_Analiser() 1022{ 1023 int col_0 = random(0, 8); 1024 int col_1 = random(0, 8); 1025 int col_2 = random(0, 8); 1026 int col_3 = random(0, 8); 1027 int col_4 = random(0, 8); 1028 int col_5 = random(0, 8); 1029 int col_6 = random(0, 8); 1030 int col_7 = random(0, 8); 1031 // Clear all leds 1032 for (int i = 0; i < 8; i++) 1033 { 1034 LEDS[i] = 0; 1035 } 1036 // Set first column 1037 for (int c = 0; c <= col_0; c++) 1038 { 1039 LEDS[c] = 1; 1040 } 1041 // Set second column 1042 for (int c = 0; c <= col_1; c++) 1043 { 1044 LEDS[c] |= 0x2; 1045 } 1046 // Set third column 1047 for (int c = 0; c <= col_2; c++) 1048 { 1049 LEDS[c] |= 0x4; 1050 } 1051 // Set fourth column 1052 for (int c = 0; c <= col_3; c++) 1053 { 1054 LEDS[c] |= 0x8; 1055 } 1056 // Set fifth column 1057 for (int c = 0; c <= col_4; c++) 1058 { 1059 LEDS[c] |= 0x10; 1060 } 1061 // Set sixth column 1062 for (int c = 0; c <= col_5; c++) 1063 { 1064 LEDS[c] |= 0x20; 1065 } 1066 // Set seventh column 1067 for (int c = 0; c <= col_6; c++) 1068 { 1069 LEDS[c] |= 0x40; 1070 } 1071 // Set eighth column 1072 for (int c = 0; c <= col_7; c++) 1073 { 1074 LEDS[c] |= 0x80; 1075 } 1076} 1077void UpdateProgram_Wave() 1078{ 1079 int col_0 = 0; 1080 int col_1 = 0; 1081 int col_2 = 0; 1082 int col_3 = 0; 1083 int col_4 = 0; 1084 int col_5 = 0; 1085 int col_6 = 0; 1086 int col_7 = 0; 1087 1088 p_w_col0++; 1089 if (p_w_col0 > 14) 1090 { 1091 p_w_col0 = 0; 1092 } 1093 1094 if (p_w_col0 > 7) 1095 { 1096 col_0 = 14 - p_w_col0; 1097 1098 col_1 = col_0 - 1; 1099 if (col_1 < 0) 1100 { 1101 col_1 *= -1; 1102 } 1103 1104 col_2 = col_0 - 2; 1105 if (col_2 < 0) 1106 { 1107 col_2 *= -1; 1108 } 1109 1110 col_3 = col_0 - 3; 1111 if (col_3 < 0) 1112 { 1113 col_3 *= -1; 1114 } 1115 1116 col_4 = col_0 - 4; 1117 if (col_4 < 0) 1118 { 1119 col_4 *= -1; 1120 } 1121 1122 col_5 = col_0 - 5; 1123 if (col_5 < 0) 1124 { 1125 col_5 *= -1; 1126 } 1127 col_6 = col_0 - 6; 1128 if (col_6 < 0) 1129 { 1130 col_6 *= -1; 1131 } 1132 col_7 = col_0 - 7; 1133 if (col_7 < 0) 1134 { 1135 col_7 *= -1; 1136 } 1137 } 1138 else 1139 { 1140 col_0 = p_w_col0; 1141 1142 col_1 = col_0 + 1; 1143 if (col_1 > 7) 1144 { 1145 col_1 = 14 - col_1; 1146 } 1147 1148 col_2 = col_0 + 2; 1149 if (col_2 > 7) 1150 { 1151 col_2 = 14 - col_2; 1152 } 1153 1154 col_3 = col_0 + 3; 1155 if (col_3 > 7) 1156 { 1157 col_3 = 14 - col_3; 1158 } 1159 1160 col_4 = col_0 + 4; 1161 if (col_4 > 7) 1162 { 1163 col_4 = 14 - col_4; 1164 } 1165 1166 col_5 = col_0 + 5; 1167 if (col_5 > 7) 1168 { 1169 col_5 = 14 - col_5; 1170 } 1171 1172 col_6 = col_0 + 6; 1173 if (col_6 > 7) 1174 { 1175 col_6 = 14 - col_6; 1176 } 1177 1178 col_7 = col_0 + 7; 1179 if (col_7 > 7) 1180 { 1181 col_7 = 14 - col_7; 1182 } 1183 } 1184 1185 // Clear all leds 1186 for (int i = 0; i < 8; i++) 1187 { 1188 LEDS[i] = 0; 1189 } 1190 // Set first column 1191 for (int c = 0; c <= col_0; c++) 1192 { 1193 LEDS[c] = 1; 1194 } 1195 // Set second column 1196 for (int c = 0; c <= col_1; c++) 1197 { 1198 LEDS[c] |= 0x2; 1199 } 1200 // Set third column 1201 for (int c = 0; c <= col_2; c++) 1202 { 1203 LEDS[c] |= 0x4; 1204 } 1205 // Set fourth column 1206 for (int c = 0; c <= col_3; c++) 1207 { 1208 LEDS[c] |= 0x8; 1209 } 1210 // Set fifth column 1211 for (int c = 0; c <= col_4; c++) 1212 { 1213 LEDS[c] |= 0x10; 1214 } 1215 // Set sixth column 1216 for (int c = 0; c <= col_5; c++) 1217 { 1218 LEDS[c] |= 0x20; 1219 } 1220 // Set seventh column 1221 for (int c = 0; c <= col_6; c++) 1222 { 1223 LEDS[c] |= 0x40; 1224 } 1225 // Set eighth column 1226 for (int c = 0; c <= col_7; c++) 1227 { 1228 LEDS[c] |= 0x80; 1229 } 1230} 1231void UpdateProgram_MiddWave() 1232{ 1233 int col_0 = 0; 1234 int col_1 = 0; 1235 int col_2 = 0; 1236 int col_3 = 0; 1237 int col_4 = 0; 1238 int col_5 = 0; 1239 int col_6 = 0; 1240 int col_7 = 0; 1241 1242 p_w_col0++; 1243 if (p_w_col0 > 14) 1244 { 1245 p_w_col0 = 0; 1246 } 1247 1248 if (p_w_col0 > 7) 1249 { 1250 col_0 = 14 - p_w_col0; 1251 1252 col_1 = col_0 - 2; 1253 if (col_1 < 0) 1254 { 1255 col_1 *= -1; 1256 } 1257 1258 col_2 = col_0 - 4; 1259 if (col_2 < 0) 1260 { 1261 col_2 *= -1; 1262 } 1263 1264 col_3 = col_0 - 6; 1265 if (col_3 < 0) 1266 { 1267 col_3 *= -1; 1268 } 1269 1270 col_4 = col_0 - 6; 1271 if (col_4 < 0) 1272 { 1273 col_4 *= -1; 1274 } 1275 1276 col_5 = col_0 - 6; 1277 if (col_5 < 0) 1278 { 1279 col_5 *= -1; 1280 } 1281 col_6 = col_0 - 4; 1282 if (col_6 < 0) 1283 { 1284 col_6 *= -1; 1285 } 1286 col_7 = col_0 - 2; 1287 if (col_7 < 0) 1288 { 1289 col_7 *= -1; 1290 } 1291 } 1292 else 1293 { 1294 col_0 = p_w_col0; 1295 1296 col_1 = col_0 + 2; 1297 if (col_1 > 7) 1298 { 1299 col_1 = 14 - col_1; 1300 } 1301 1302 col_2 = col_0 + 4; 1303 if (col_2 > 7) 1304 { 1305 col_2 = 14 - col_2; 1306 } 1307 1308 col_3 = col_0 + 6; 1309 if (col_3 > 7) 1310 { 1311 col_3 = 14 - col_3; 1312 } 1313 1314 col_4 = col_0 + 6; 1315 if (col_4 > 7) 1316 { 1317 col_4 = 14 - col_4; 1318 } 1319 1320 col_5 = col_0 + 6; 1321 if (col_5 > 7) 1322 { 1323 col_5 = 14 - col_5; 1324 } 1325 1326 col_6 = col_0 + 4; 1327 if (col_6 > 7) 1328 { 1329 col_6 = 14 - col_6; 1330 } 1331 1332 col_7 = col_0 + 2; 1333 if (col_7 > 7) 1334 { 1335 col_7 = 14 - col_7; 1336 } 1337 } 1338 1339 // Clear all leds 1340 for (int i = 0; i < 8; i++) 1341 { 1342 LEDS[i] = 0; 1343 } 1344 // Set first column 1345 for (int c = 0; c <= col_0; c++) 1346 { 1347 LEDS[c] = 1; 1348 } 1349 // Set second column 1350 for (int c = 0; c <= col_1; c++) 1351 { 1352 LEDS[c] |= 0x2; 1353 } 1354 // Set third column 1355 for (int c = 0; c <= col_2; c++) 1356 { 1357 LEDS[c] |= 0x4; 1358 } 1359 // Set fourth column 1360 for (int c = 0; c <= col_3; c++) 1361 { 1362 LEDS[c] |= 0x8; 1363 } 1364 // Set fifth column 1365 for (int c = 0; c <= col_4; c++) 1366 { 1367 LEDS[c] |= 0x10; 1368 } 1369 // Set sixth column 1370 for (int c = 0; c <= col_5; c++) 1371 { 1372 LEDS[c] |= 0x20; 1373 } 1374 // Set seventh column 1375 for (int c = 0; c <= col_6; c++) 1376 { 1377 LEDS[c] |= 0x40; 1378 } 1379 // Set eighth column 1380 for (int c = 0; c <= col_7; c++) 1381 { 1382 LEDS[c] |= 0x80; 1383 } 1384} 1385void UpdateProgram_FILL() 1386{ 1387 int col_0 = 0; 1388 int col_1 = 0; 1389 int col_2 = 0; 1390 int col_3 = 0; 1391 int col_4 = 0; 1392 int col_5 = 0; 1393 int col_6 = 0; 1394 int col_7 = 0; 1395 1396 p_w_col0++; 1397 if (p_w_col0 >= 64) 1398 { 1399 p_w_col0 = 0; 1400 } 1401 1402 col_0 = p_w_col0; 1403 if (col_0 > 7) 1404 col_0 = 7; 1405 1406 col_1 = p_w_col0 - 8; 1407 if (col_1 < 0) 1408 { 1409 col_1 = 0; 1410 } 1411 else if (col_1 > 7) 1412 { 1413 col_1 = 7; 1414 } 1415 1416 col_2 = p_w_col0 - 16; 1417 if (col_2 < 0) 1418 { 1419 col_2 = 0; 1420 } 1421 else if (col_2 > 7) 1422 { 1423 col_2 = 7; 1424 } 1425 1426 col_3 = p_w_col0 - 24; 1427 if (col_3 < 0) 1428 { 1429 col_3 = 0; 1430 } 1431 else if (col_3 > 7) 1432 { 1433 col_3 = 7; 1434 } 1435 1436 col_4 = p_w_col0 - 32; 1437 if (col_4 < 0) 1438 { 1439 col_4 = 0; 1440 } 1441 else if (col_4 > 7) 1442 { 1443 col_4 = 7; 1444 } 1445 1446 col_5 = p_w_col0 - 40; 1447 if (col_5 < 0) 1448 { 1449 col_5 = 0; 1450 } 1451 else if (col_5 > 7) 1452 { 1453 col_5 = 7; 1454 } 1455 1456 col_6 = p_w_col0 - 48; 1457 if (col_6 < 0) 1458 { 1459 col_6 = 0; 1460 } 1461 else if (col_6 > 7) 1462 { 1463 col_6 = 7; 1464 } 1465 1466 col_7 = p_w_col0 - 56; 1467 if (col_7 < 0) 1468 { 1469 col_7 = 0; 1470 } 1471 else if (col_7 > 7) 1472 { 1473 col_7 = 7; 1474 } 1475 1476 // Clear all leds 1477 for (int i = 0; i < 8; i++) 1478 { 1479 LEDS[i] = 0; 1480 } 1481 // Set first column 1482 for (int c = 0; c <= col_0; c++) 1483 { 1484 LEDS[c] = 1; 1485 } 1486 // Set second column 1487 for (int c = 0; c <= col_1; c++) 1488 { 1489 LEDS[c] |= 0x2; 1490 } 1491 // Set third column 1492 for (int c = 0; c <= col_2; c++) 1493 { 1494 LEDS[c] |= 0x4; 1495 } 1496 // Set fourth column 1497 for (int c = 0; c <= col_3; c++) 1498 { 1499 LEDS[c] |= 0x8; 1500 } 1501 // Set fifth column 1502 for (int c = 0; c <= col_4; c++) 1503 { 1504 LEDS[c] |= 0x10; 1505 } 1506 // Set sixth column 1507 for (int c = 0; c <= col_5; c++) 1508 { 1509 LEDS[c] |= 0x20; 1510 } 1511 // Set seventh column 1512 for (int c = 0; c <= col_6; c++) 1513 { 1514 LEDS[c] |= 0x40; 1515 } 1516 // Set eighth column 1517 for (int c = 0; c <= col_7; c++) 1518 { 1519 LEDS[c] |= 0x80; 1520 } 1521} 1522void UpdateProgram_Random() 1523{ 1524 for (int i = 0; i < 8; i++) 1525 { 1526 LEDS[i] = random(0, 0xFF); 1527 } 1528} 1529void UpdateProgram_River() 1530{ 1531 p_r_i++; 1532 if (p_r_i >= 8) 1533 p_r_i = 0; 1534 1535 int sh1 = (p_r_i + 1); 1536 int sh2 = (p_r_i + 2); 1537 int sh3 = (p_r_i + 3); 1538 int sh4 = (p_r_i + 4); 1539 int sh5 = (p_r_i + 5); 1540 int sh6 = (p_r_i + 6); 1541 int sh7 = (p_r_i + 7); 1542 1543 if (sh1 > 7) 1544 sh1 -= 7; 1545 if (sh2 > 7) 1546 sh2 -= 7; 1547 if (sh3 > 7) 1548 sh3 -= 7; 1549 if (sh4 > 7) 1550 sh4 -= 7; 1551 if (sh5 > 7) 1552 sh5 -= 7; 1553 if (sh6 > 7) 1554 sh6 -= 7; 1555 if (sh7 > 7) 1556 sh7 -= 7; 1557 LEDS[0] = 1 << p_r_i; 1558 LEDS[1] = 1 << sh6; 1559 LEDS[2] = 1 << sh4; 1560 LEDS[3] = 1 << sh3; 1561 LEDS[4] = 1 << sh6; 1562 LEDS[5] = 1 << sh2; 1563 LEDS[6] = 1 << sh1; 1564 LEDS[7] = 1 << sh7; 1565} 1566void UpdateProgram_Greens() 1567{ 1568 LEDS[0] = 0; 1569 LEDS[1] = 0; 1570 LEDS[2] = 0; 1571 LEDS[3] = random(0, 0xFF); 1572 LEDS[4] = random(0, 0xFF); 1573 LEDS[5] = random(0, 0xFF); 1574 LEDS[6] = 0; 1575 LEDS[7] = 0; 1576} 1577void UpdateProgram_Yellows() 1578{ 1579 LEDS[0] = 0; 1580 LEDS[1] = random(0, 0xFF); 1581 LEDS[2] = random(0, 0xFF); 1582 LEDS[3] = 0; 1583 LEDS[4] = 0; 1584 LEDS[5] = 0; 1585 LEDS[6] = 0; 1586 LEDS[7] = 0; 1587} 1588void UpdateProgram_Reds() 1589{ 1590 LEDS[0] = 0; 1591 LEDS[1] = 0; 1592 LEDS[2] = 0; 1593 LEDS[3] = 0; 1594 LEDS[4] = 0; 1595 LEDS[5] = 0; 1596 LEDS[6] = random(0, 0xFF); 1597 LEDS[7] = random(0, 0xFF); 1598} 1599void UpdateProgram_AlphaBet() 1600{ 1601 p_a_counter--; 1602 if (p_a_counter <= 0) 1603 { 1604 p_a_counter = p_a_wait; 1605 switch (p_a_char_index) 1606 { 1607 case 0 : SetChar("a"); break; 1608 case 1 : SetChar("b"); break; 1609 case 2 : SetChar("c"); break; 1610 case 3 : SetChar("d"); break; 1611 case 4 : SetChar("e"); break; 1612 case 5 : SetChar("f"); break; 1613 case 6 : SetChar("g"); break; 1614 case 7 : SetChar("h"); break; 1615 case 8 : SetChar("i"); break; 1616 case 9 : SetChar("j"); break; 1617 case 10 : SetChar("k"); break; 1618 case 11 : SetChar("l"); break; 1619 case 12: SetChar("m"); break; 1620 case 13 : SetChar("n"); break; 1621 case 14: SetChar("o"); break; 1622 case 15 : SetChar("p"); break; 1623 case 16 : SetChar("q"); break; 1624 case 17 : SetChar("r"); break; 1625 case 18 : SetChar("s"); break; 1626 case 19 : SetChar("t"); break; 1627 case 20 : SetChar("u"); break; 1628 case 21 : SetChar("v"); break; 1629 case 22 : SetChar("w"); break; 1630 case 23 : SetChar("x"); break; 1631 case 24 : SetChar("y"); break; 1632 case 25 : SetChar("z"); break; 1633 case 26 : SetChar("1"); break; 1634 case 27 : SetChar("2"); break; 1635 case 28 : SetChar("3"); break; 1636 case 29 : SetChar("4"); break; 1637 case 30 : SetChar("5"); break; 1638 case 31 : SetChar("6"); break; 1639 case 32 : SetChar("7"); break; 1640 case 33 : SetChar("8"); break; 1641 case 34 : SetChar("9"); break; 1642 case 35 : SetChar("0"); break; 1643 } 1644 p_a_char_index++; 1645 if (p_a_char_index > 35) 1646 p_a_char_index = 0; 1647 } 1648} 1649void UpdateProgram_CountNumbers() 1650{ 1651 p_a_counter--; 1652 if (p_a_counter <= 0) 1653 { 1654 p_a_counter = p_a_wait; 1655 switch (p_a_char_index) 1656 { 1657 case 0 : SetChar("0"); break; 1658 case 1 : SetChar("1"); break; 1659 case 2 : SetChar("2"); break; 1660 case 3 : SetChar("3"); break; 1661 case 4 : SetChar("4"); break; 1662 case 5 : SetChar("5"); break; 1663 case 6 : SetChar("6"); break; 1664 case 7 : SetChar("7"); break; 1665 case 8 : SetChar("8"); break; 1666 case 9 : SetChar("9"); break; 1667 } 1668 p_a_char_index++; 1669 if (p_a_char_index > 9) 1670 p_a_char_index = 0; 1671 } 1672} 1673void UpdateProgram_ILoveYou() 1674{ 1675 p_a_counter--; 1676 if (p_a_counter <= 0) 1677 { 1678 p_a_counter = p_a_wait; 1679 switch (p_a_char_index) 1680 { 1681 1682 case 0 : SetChar("i"); break; 1683 case 1 : SetChar("l"); break; 1684 case 2: SetChar("o"); break; 1685 case 3 : SetChar("v"); break; 1686 case 4 : SetChar("e"); break; 1687 case 5 : SetChar("-"); break; 1688 case 6 : SetChar("y"); break; 1689 case 7 : SetChar("o"); break; 1690 case 8 : SetChar("u"); break; 1691 case 9 : SetChar("heart"); break; 1692 case 10 : SetChar("heart"); break; 1693 case 11 : SetChar("heartfull"); break; 1694 case 12 : SetChar("heartfull"); break; 1695 } 1696 p_a_char_index++; 1697 if (p_a_char_index > 12) 1698 p_a_char_index = 0; 1699 } 1700} 1701void UpdateProgram_Circle() 1702{ 1703 switch (p_c_index) 1704 { 1705 case 0 : 1706 { 1707 LEDS [7] = B00000000; 1708 LEDS [6] = B00000000; 1709 LEDS [5] = B00000000; 1710 LEDS [4] = B00011000; 1711 LEDS [3] = B00011000; 1712 LEDS [2] = B00000000; 1713 LEDS [1] = B00000000; 1714 LEDS [0] = B00000000; 1715 break; 1716 } 1717 case 1 : 1718 { 1719 LEDS [7] = B00000000; 1720 LEDS [6] = B00000000; 1721 LEDS [5] = B00111100; 1722 LEDS [4] = B00100100; 1723 LEDS [3] = B00100100; 1724 LEDS [2] = B00111100; 1725 LEDS [1] = B00000000; 1726 LEDS [0] = B00000000; 1727 break; 1728 } 1729 case 2 : 1730 { 1731 LEDS [7] = B00000000; 1732 LEDS [6] = B01111110; 1733 LEDS [5] = B01000010; 1734 LEDS [4] = B01000010; 1735 LEDS [3] = B01000010; 1736 LEDS [2] = B01000010; 1737 LEDS [1] = B01111110; 1738 LEDS [0] = B00000000; 1739 break; 1740 } 1741 case 3 : 1742 { 1743 LEDS [7] = B11111111; 1744 LEDS [6] = B10000001; 1745 LEDS [5] = B10000001; 1746 LEDS [4] = B10000001; 1747 LEDS [3] = B10000001; 1748 LEDS [2] = B10000001; 1749 LEDS [1] = B10000001; 1750 LEDS [0] = B11111111; 1751 break; 1752 } 1753 } 1754 if (!p_c_flp) 1755 { 1756 p_c_index ++; 1757 if (p_c_index > 3) 1758 { 1759 p_c_index = 3; 1760 p_c_flp = !p_c_flp; 1761 } 1762 } 1763 else 1764 { 1765 p_c_index --; 1766 if (p_c_index < 0) 1767 { 1768 p_c_index = 0; 1769 p_c_flp = !p_c_flp; 1770 } 1771 } 1772} 1773void UpdateProgram_Tunnle() 1774{ 1775 switch (p_c_index) 1776 { 1777 case 0 : 1778 { 1779 LEDS [7] = B00000000; 1780 LEDS [6] = B00000000; 1781 LEDS [5] = B00000000; 1782 LEDS [4] = B00011000; 1783 LEDS [3] = B00011000; 1784 LEDS [2] = B00000000; 1785 LEDS [1] = B00000000; 1786 LEDS [0] = B00000000; 1787 break; 1788 } 1789 case 1 : 1790 { 1791 LEDS [7] = B00000000; 1792 LEDS [6] = B00000000; 1793 LEDS [5] = B00111100; 1794 LEDS [4] = B00100100; 1795 LEDS [3] = B00100100; 1796 LEDS [2] = B00111100; 1797 LEDS [1] = B00000000; 1798 LEDS [0] = B00000000; 1799 break; 1800 } 1801 case 2 : 1802 { 1803 LEDS [7] = B00000000; 1804 LEDS [6] = B01111110; 1805 LEDS [5] = B01000010; 1806 LEDS [4] = B01000010; 1807 LEDS [3] = B01000010; 1808 LEDS [2] = B01000010; 1809 LEDS [1] = B01111110; 1810 LEDS [0] = B00000000; 1811 break; 1812 } 1813 case 3 : 1814 { 1815 LEDS [7] = B11111111; 1816 LEDS [6] = B10000001; 1817 LEDS [5] = B10000001; 1818 LEDS [4] = B10000001; 1819 LEDS [3] = B10000001; 1820 LEDS [2] = B10000001; 1821 LEDS [1] = B10000001; 1822 LEDS [0] = B11111111; 1823 break; 1824 } 1825 } 1826 1827 p_c_index ++; 1828 if (p_c_index > 3) 1829 { 1830 p_c_index = 0; 1831 } 1832} 1833void UpdateProgram_Heart1() 1834{ 1835 switch (p_c_index) 1836 { 1837 case 0 : 1838 { 1839 LEDS [7] = B00000000; 1840 LEDS [6] = B00000000; 1841 LEDS [5] = B00000000; 1842 LEDS [4] = B00111100; 1843 LEDS [3] = B00011000; 1844 LEDS [2] = B00000000; 1845 LEDS [1] = B00000000; 1846 LEDS [0] = B00000000; 1847 break; 1848 } 1849 case 1 : 1850 { 1851 LEDS [7] = B00000000; 1852 LEDS [6] = B00000000; 1853 LEDS [5] = B00100100; 1854 LEDS [4] = B00111100; 1855 LEDS [3] = B00100100; 1856 LEDS [2] = B00011000; 1857 LEDS [1] = B00000000; 1858 LEDS [0] = B00000000; 1859 break; 1860 } 1861 case 2 : 1862 { 1863 LEDS [7] = B00000000; 1864 LEDS [6] = B00000000; 1865 LEDS [5] = B01100110; 1866 LEDS [4] = B01011010; 1867 LEDS [3] = B01000010; 1868 LEDS [2] = B00100100; 1869 LEDS [1] = B00011000; 1870 LEDS [0] = B00000000; 1871 break; 1872 } 1873 case 3 : 1874 { 1875 LEDS [7] = B00000000; 1876 LEDS [6] = B11100111; 1877 LEDS [5] = B10011001; 1878 LEDS [4] = B10000001; 1879 LEDS [3] = B10000001; 1880 LEDS [2] = B01000010; 1881 LEDS [1] = B00100100; 1882 LEDS [0] = B00011000; 1883 break; 1884 } 1885 } 1886 if (!p_c_flp) 1887 { 1888 p_c_index ++; 1889 if (p_c_index > 3) 1890 { 1891 p_c_index = 3; 1892 p_c_flp = !p_c_flp; 1893 } 1894 } 1895 else 1896 { 1897 p_c_index --; 1898 if (p_c_index < 0) 1899 { 1900 p_c_index = 0; 1901 p_c_flp = !p_c_flp; 1902 } 1903 } 1904} 1905void UpdateProgram_Heart2() 1906{ 1907 switch (p_c_index) 1908 { 1909 case 0 : 1910 { 1911 LEDS [7] = B00000000; 1912 LEDS [6] = B00000000; 1913 LEDS [5] = B00000000; 1914 LEDS [4] = B00111100; 1915 LEDS [3] = B00011000; 1916 LEDS [2] = B00000000; 1917 LEDS [1] = B00000000; 1918 LEDS [0] = B00000000; 1919 break; 1920 } 1921 case 1 : 1922 { 1923 LEDS [7] = B00000000; 1924 LEDS [6] = B00000000; 1925 LEDS [5] = B00100100; 1926 LEDS [4] = B00111100; 1927 LEDS [3] = B00100100; 1928 LEDS [2] = B00011000; 1929 LEDS [1] = B00000000; 1930 LEDS [0] = B00000000; 1931 break; 1932 } 1933 case 2 : 1934 { 1935 LEDS [7] = B00000000; 1936 LEDS [6] = B00000000; 1937 LEDS [5] = B01100110; 1938 LEDS [4] = B01011010; 1939 LEDS [3] = B01000010; 1940 LEDS [2] = B00100100; 1941 LEDS [1] = B00011000; 1942 LEDS [0] = B00000000; 1943 break; 1944 } 1945 case 3 : 1946 { 1947 LEDS [7] = B00000000; 1948 LEDS [6] = B11100111; 1949 LEDS [5] = B10011001; 1950 LEDS [4] = B10000001; 1951 LEDS [3] = B10000001; 1952 LEDS [2] = B01000010; 1953 LEDS [1] = B00100100; 1954 LEDS [0] = B00011000; 1955 break; 1956 } 1957 } 1958 1959 p_c_index ++; 1960 if (p_c_index > 3) 1961 { 1962 p_c_index = 0; 1963 } 1964 1965} 1966void UpdateProgram_Heart3() 1967{ 1968 switch (p_c_index) 1969 { 1970 case 0 : 1971 { 1972 LEDS [7] = B00000000; 1973 LEDS [6] = B00000000; 1974 LEDS [5] = B00000000; 1975 LEDS [4] = B00111100; 1976 LEDS [3] = B00011000; 1977 LEDS [2] = B00000000; 1978 LEDS [1] = B00000000; 1979 LEDS [0] = B00000000; 1980 break; 1981 } 1982 case 1 : 1983 { 1984 LEDS [7] = B00000000; 1985 LEDS [6] = B00000000; 1986 LEDS [5] = B00100100; 1987 LEDS [4] = B00111100; 1988 LEDS [3] = B00111100; 1989 LEDS [2] = B00011000; 1990 LEDS [1] = B00000000; 1991 LEDS [0] = B00000000; 1992 break; 1993 } 1994 case 2 : 1995 { 1996 LEDS [7] = B00000000; 1997 LEDS [6] = B00000000; 1998 LEDS [5] = B01100110; 1999 LEDS [4] = B01111110; 2000 LEDS [3] = B01111110; 2001 LEDS [2] = B00111100; 2002 LEDS [1] = B00011000; 2003 LEDS [0] = B00000000; 2004 break; 2005 } 2006 case 3 : 2007 { 2008 LEDS [7] = B00000000; 2009 LEDS [6] = B11100111; 2010 LEDS [5] = B11111111; 2011 LEDS [4] = B11111111; 2012 LEDS [3] = B11111111; 2013 LEDS [2] = B01111110; 2014 LEDS [1] = B00111100; 2015 LEDS [0] = B00011000; 2016 break; 2017 } 2018 } 2019 if (!p_c_flp) 2020 { 2021 p_c_index ++; 2022 if (p_c_index > 3) 2023 { 2024 p_c_index = 3; 2025 p_c_flp = !p_c_flp; 2026 } 2027 } 2028 else 2029 { 2030 p_c_index --; 2031 if (p_c_index < 0) 2032 { 2033 p_c_index = 0; 2034 p_c_flp = !p_c_flp; 2035 } 2036 } 2037} 2038void UpdateProgram_Heart4() 2039{ 2040 switch (p_c_index) 2041 { 2042 case 0 : 2043 { 2044 LEDS [7] = B00000000; 2045 LEDS [6] = B00000000; 2046 LEDS [5] = B00000000; 2047 LEDS [4] = B00111100; 2048 LEDS [3] = B00011000; 2049 LEDS [2] = B00000000; 2050 LEDS [1] = B00000000; 2051 LEDS [0] = B00000000; 2052 break; 2053 } 2054 case 1 : 2055 { 2056 LEDS [7] = B00000000; 2057 LEDS [6] = B00000000; 2058 LEDS [5] = B00100100; 2059 LEDS [4] = B00111100; 2060 LEDS [3] = B00111100; 2061 LEDS [2] = B00011000; 2062 LEDS [1] = B00000000; 2063 LEDS [0] = B00000000; 2064 break; 2065 } 2066 case 2 : 2067 { 2068 LEDS [7] = B00000000; 2069 LEDS [6] = B00000000; 2070 LEDS [5] = B01100110; 2071 LEDS [4] = B01111110; 2072 LEDS [3] = B01111110; 2073 LEDS [2] = B00111100; 2074 LEDS [1] = B00011000; 2075 LEDS [0] = B00000000; 2076 break; 2077 } 2078 case 3 : 2079 { 2080 LEDS [7] = B00000000; 2081 LEDS [6] = B11100111; 2082 LEDS [5] = B11111111; 2083 LEDS [4] = B11111111; 2084 LEDS [3] = B11111111; 2085 LEDS [2] = B01111110; 2086 LEDS [1] = B00111100; 2087 LEDS [0] = B00011000; 2088 break; 2089 } 2090 } 2091 2092 p_c_index ++; 2093 if (p_c_index > 3) 2094 { 2095 p_c_index = 0; 2096 } 2097 2098} 2099 2100void UpdateProgram_CyclePrograms() 2101{ 2102 p_c_counter++; 2103 if (p_c_counter >= p_c_timer) 2104 { 2105 p_c_counter = 0; 2106 p_c_program_index++; 2107 if (p_c_program_index > 20) 2108 p_c_program_index = 0; 2109 } 2110 ChooseProgram( p_c_program_index); 2111} 2112void UpdateProgram_CycleProgramsRandom() 2113{ 2114 p_c_counter++; 2115 if (p_c_counter >= p_c_timer) 2116 { 2117 p_c_counter = 0; 2118 p_c_program_index = random(0, 20); 2119 if (p_c_program_index > 20) 2120 p_c_program_index = 0; 2121 } 2122 ChooseProgram( p_c_program_index); 2123} 2124 2125// DO LOOP 2126void loop() { 2127 Render(); 2128 UpdateLCD(); 2129 HandleInputs(); 2130 UpdateProgram(); 2131} 2132
Downloadable files
Bredboard connection
This is how we would make the project connections on bredboards.
Bredboard connection
The project in fretzing project file.
you can use fretzing to edit the project as you like using this saved project file.
The project in fretzing project file.
Bredboard connection
This is how we would make the project connections on bredboards.
Bredboard connection
The project in fretzing project file.
you can use fretzing to edit the project as you like using this saved project file.
The project in fretzing project file.
Comments
Only logged in users can leave comments