Global variablesunsigned long time;// LiquidCrystal display with:// rs on pin 12// rw on pin 11// enable on pin 2// dbs 3, 4, 5, 6, 7, 8, 9, 10LiquidCrystal lcd(12, 11, 2, 3, 4, 5, 6, 7, 8, 9, 10);// Analog configurationunsigned int analogCmd[QUANTITY_COMMANDS];unsigned int analogSpeed = 0;// Control commandsboolean changingSpeed = true;boolean readingSerial = false;boolean pressedCmd[QUANTITY_COMMANDS];unsigned int lastSpeed = 0;// Massageschar currentMessage[400] = "No messages.";unsigned int currentMessageLenght;// ------------------------------------------------------------------------ \\// Programvoid setup() { Serial.begin(SERIAL_BOUND); pinMode(DEBUG_PIN, OUTPUT); smartDelay(10); lastSpeed = analogSpeed; presentation(); changingSpeed = false;}void loop() { // Show current message clearLcd(); writeLongTextInLcd(currentMessage); smartDelay(applySpeed(7000)); }void presentation() { lcd.clear(); writeLongTextInLcd("Twitter Hardwareby Bruno Soares"); smartDelay(3000);}void refreshAnalogVars() { analogCmd[COMMAND_RIGHT] = analogRead(ANALOG_PIN_COMMAND_RIGHT); analogCmd[COMMAND_LEFT] = analogRead(ANALOG_PIN_COMMAND_LEFT); analogSpeed = analogRead(ANALOG_PIN_SPEED);}// ------------------------------------------------------------------------ \\// [INI] Commandsvoid detectCommand() { unsigned int i = 0; while (i < QUANTITY_COMMANDS) { if (analogCmd[i] > 500 && !pressedCmd[i]) { executeCommand(i); } i++; }}void executeCommand(int command) { pressedCmd[command] = true; digitalWrite(DEBUG_PIN, 1); if (command == 0) { animateNext(); } else { animatePrevious(); } currentMessage[0] = 'L'; currentMessage[1] = 'o'; currentMessage[2] = 'a'; currentMessage[3] = 'd'; currentMessage[4] = 'i'; currentMessage[5] = 'n'; currentMessage[6] = 'g'; currentMessage[7] = '\0'; currentMessageLenght = 7; Serial.print(command); while (analogCmd[command] > 500) { smartDelay(4); } pressedCmd[command] = false; digitalWrite(DEBUG_PIN, 0);}void animateNext() { for (unsigned int i = 0; i < LCD_COLUMNS + ANIMATE_CMD_WIDTH; i++) { if (i < LCD_COLUMNS) { lcd.setCursor(i, 0); lcd.print(">"); lcd.setCursor(i, 1); lcd.print(">"); } delay(5); if (i - ANIMATE_CMD_WIDTH >= 0) { lcd.setCursor(i - ANIMATE_CMD_WIDTH, 0); lcd.print(" "); lcd.setCursor(i - ANIMATE_CMD_WIDTH, 1); lcd.print(" "); } delay(30); }}void animatePrevious() { for (int i = LCD_COLUMNS; i >= -ANIMATE_CMD_WIDTH; i--) { if (i >= 0 && i < LCD_COLUMNS) { lcd.setCursor(i, 0); lcd.print("<"); lcd.setCursor(i, 1); lcd.print("<"); } delay(5); if (i + ANIMATE_CMD_WIDTH < LCD_COLUMNS && i + ANIMATE_CMD_WIDTH >= 0) { lcd.setCursor(i + ANIMATE_CMD_WIDTH, 0); lcd.print(" "); lcd.setCursor(i + ANIMATE_CMD_WIDTH, 1); lcd.print(" "); } delay(30); }}// [END] Commands// ------------------------------------------------------------------------ \\// [INI] Messagesvoid detectSerialMessage() { if (Serial.available() > 0 && !readingSerial) { if (Serial.read() == MESSAGE_START) { serialReadMessage(); } }}void serialReadMessage() { digitalWrite(DEBUG_PIN, 1); readingSerial = true; currentMessageLenght = 0; iniReading: if (Serial.available() > 0) { unsigned int _char = Serial.read(); if (_char == MESSAGE_END) { goto endReading; } else { currentMessage[currentMessageLenght++] = _char; delay(2); goto iniReading; } } goto iniReading; endReading: currentMessage[currentMessageLenght] = '\0'; digitalWrite(DEBUG_PIN, 0); readingSerial = false;}// [END] Messages// ------------------------------------------------------------------------ \\// [INI] LCD manipulationvoid writeLongTextInLcd(char text[]) { writeInit: clearLcd(); unsigned int cml = currentMessageLenght; int loops = -1; unsigned int chars = 1; while (text[loops++ + 1] != 0) { if (chars == 17) { lcd.setCursor(0, 1); smartDelay(applySpeed(600)); if (cml != currentMessageLenght) goto writeInit; } else if (chars == 33) { smartDelay(applySpeed(3000)); clearLcd(); if (cml != currentMessageLenght) goto writeInit; chars = 1; } lcd.print(text[loops]); smartDelay(applySpeed(60)); if (cml != currentMessageLenght) goto writeInit; chars++; } Serial.print(2);}void writeInLcd(char text[], int quantity) { for (unsigned int i = 0; i < quantity; i++) { if (text[i] == 0) { do { lcd.print(" "); } while (i++ < quantity); break; } else { lcd.print(text[i]); } } delay(2); //smartDelay(5);}void clearLcd() { lcd.setCursor(0, 0); smartDelay(5); lcd.print(" "); smartDelay(applySpeed(400)); lcd.setCursor(0, 1); smartDelay(5); lcd.print(" "); lcd.setCursor(0, 0); smartDelay(applySpeed(0));}// [END] LCD