#define pin_A_I_R 13 #define pin_B_J_S 12 #define pin_C_K_T 8 #define pin_D_L_U 7 #define pin_E_M_V 6 #define pin_F_N_W 5 #define pin_G_O_X 4 #define pin_H_P_Y 3 #define pin_Q_Z A0 //all analog pins can be used as digital //these ones need to be a pwm arduino pin #define row_1 11 #define row_2 10 #define row_3 9 int buttonTimes = 0; // stores how many times the button was pressed String text = "feliz aniversario"; // first text to appear int i; // i is used in a loop, I'm declaring it here because we will eventually need to break the loop void setup() { // set all pins as outputs pinMode(pin_A_I_R, OUTPUT); pinMode(pin_B_J_S, OUTPUT); pinMode(pin_C_K_T, OUTPUT); pinMode(pin_D_L_U, OUTPUT); pinMode(pin_E_M_V, OUTPUT); pinMode(pin_F_N_W, OUTPUT); pinMode(pin_G_O_X, OUTPUT); pinMode(pin_H_P_Y, OUTPUT); pinMode(pin_Q_Z, OUTPUT); pinMode(row_1, OUTPUT); pinMode(row_2, OUTPUT); pinMode(row_3, OUTPUT); //set interrupt pin on pin 2 (which is 0 for the interrupt function) attachInterrupt(0, interrupcao, FALLING); } void loop() { text.toUpperCase(); //change all letters uppercase executeEffect(text); // executes effect } //interrupt function void interrupcao(){ i = 100; //every time you press the button you break the for loop that shows the letter static unsigned long last_interrupt_time = 0; //this sets the configuration to count how long the button was pressed unsigned long interrupt_time = millis(); if (interrupt_time - last_interrupt_time > 200) //this is to prevent debounce through software { buttonTimes = buttonTimes + 1; //increments each time the button is pressed if (buttonTimes > 7) { // 7 is the number of strings that will be showed. If it exceeds 7 goes back to 0, you can change it to more or less than 7 buttonTimes = 0; } switch (buttonTimes) { // here you insert the sentences you want to show, lowercase uppercase it doesn't matter case 0: // if you want to add more you just need to add one more case # text = "happy birthday "; // if you want to remove just erase de cases and change the number of strings above break; case 1: text = "help me "; break; case 2: text = "abcdefghijklmnopqrstuvwxyz"; break; case 3: text = "merry christmas "; break; case 4: text = "hey there "; break; case 5: text = "its me"; break; case 6: text = "dont look behind you "; break; case 7: text = "kidding "; break; } } last_interrupt_time = interrupt_time; } void rowActivation(int row){ //this function activates each row if(row == 1){ digitalWrite(row_2, LOW); digitalWrite(row_3, LOW); fadingInOut(row_1); // here it fades the led through pwm signal } else if (row == 2){ digitalWrite(row_1, LOW); digitalWrite(row_3, LOW); fadingInOut(row_2); } else if(row == 3){ digitalWrite(row_1, LOW); digitalWrite(row_2, LOW); fadingInOut(row_3); } } // fading function. this happens in a 465ms interval, if you change the time of the columns down there you need to change up here too void fadingInOut(int row){ for(int fadeValue = 0 ; fadeValue <= 155; fadeValue +=5) { analogWrite(row, fadeValue); delay(15); } for(int fadeValue = 155 ; fadeValue >= 0; fadeValue -=5) { analogWrite(row, fadeValue); delay(15); } } //this one activates the letter of each string. void activateLetter(char letter, int on, int off, int row){ if(letter == 'A' or letter == 'I' or letter == 'R'){ //check the column digitalWrite(pin_A_I_R, HIGH); // activates the column rowActivation(row); // activates the row delay(on); // wait some time digitalWrite(pin_A_I_R, LOW); //deactivates the column (the row deactivates itself at the end of the fading delay(off); // time between each letter } if(letter == 'B' or letter == 'J' or letter == 'S'){ digitalWrite(pin_B_J_S, HIGH); rowActivation(row); delay(on); digitalWrite(pin_B_J_S, LOW); delay(off); } if(letter == 'C' or letter == 'K' or letter == 'T'){ digitalWrite(pin_C_K_T, HIGH); rowActivation(row); delay(on); digitalWrite(pin_C_K_T, LOW); delay(off); } if(letter == 'D' or letter =='L' or letter == 'U'){ digitalWrite(pin_D_L_U, HIGH); rowActivation(row); delay(on); digitalWrite(pin_D_L_U, LOW); delay(off); } if(letter == 'E' or letter == 'M' or letter == 'V'){ digitalWrite(pin_E_M_V, HIGH); rowActivation(row); delay(on); digitalWrite(pin_E_M_V, LOW); delay(off); } if(letter == 'F' or letter == 'N' or letter == 'W'){ digitalWrite(pin_F_N_W, HIGH); rowActivation(row); delay(on); digitalWrite(pin_F_N_W, LOW); delay(off); } if(letter == 'G' or letter == 'O' or letter == 'X'){ digitalWrite(pin_G_O_X, HIGH); rowActivation(row); delay(on); digitalWrite(pin_G_O_X, LOW); delay(off); } if(letter == 'H' or letter == 'P' or letter == 'Y'){ digitalWrite(pin_H_P_Y, HIGH); rowActivation(row); delay(on); digitalWrite(pin_H_P_Y, LOW); delay(off); } if(letter == 'Q' or letter == 'Z'){ digitalWrite(pin_Q_Z, HIGH); rowActivation(row); delay(on); digitalWrite(pin_Q_Z, LOW); delay(off); } } //this is the most important function void executeEffect(String text){ for(i = 0; i < text.length(); i++){ //gets the size of the string and check letter by letter untill the string is over switch(text[i]){ case 'A': activateLetter('A', 500, 20, 1); //activates A, turns the led on for 500ms, turns it off for 20ms, says it belongs to row 1 break; case 'B': activateLetter('B', 500, 20, 1); break; case 'C': activateLetter('C', 500, 20, 1); break; case 'D': activateLetter('D', 500, 20, 1); break; case 'E': activateLetter('E', 500, 20, 1); break; case 'F': activateLetter('F', 500, 20, 1); break; case 'G': activateLetter('G', 500, 20, 1); break; case 'H': activateLetter('H', 500, 20, 1); break; case 'I': activateLetter('I', 500, 20, 2); break; case 'J': activateLetter('J', 500, 20, 2); break; case 'K': activateLetter('K', 500, 20, 2); break; case 'L': activateLetter('L', 500, 20, 2); break; case 'M': activateLetter('M', 500, 20, 2); break; case 'N': activateLetter('N', 500, 20, 2); break; case 'O': activateLetter('O', 500, 20, 2); break; case 'P': activateLetter('P', 500, 20, 2); break; case 'Q': activateLetter('Q', 500, 20, 2); break; case 'R': activateLetter('R', 500, 20, 3); break; case 'S': activateLetter('S', 500, 20, 3); break; case 'T': activateLetter('T', 500, 20, 3); break; case 'U': activateLetter('U', 500, 20, 3); break; case 'V': activateLetter('V', 500, 20, 3); break; case 'W': activateLetter('W', 500, 20, 3); break; case 'X': activateLetter('X', 500, 20, 3); break; case 'Y': activateLetter('Y', 500, 20, 3); break; case 'Z': activateLetter('Z', 500, 20, 3); break; case ' ': // if there's a space between letter wait for 500ms till the next one delay(500); break; } } }