Paso 3: Firmware
Inicializar el LCD
Establecer algunas constantes que se utilizan en el código
Imprimir un mensaje inicial a la LCD
Configurar el servo y arriar la bandera
Espere cinco segundos para la secuencia de comandos para la puesta en marcha en el servidor PC
Bucle:
Solicitar estado de servidor y esperar respuesta
Si nuevos tweets: izar la bandera y mostrar el número de tweets
otra cosa: arriar la bandera y mostrar la etiqueta de búsqueda
Solicitar el siguiente tweet desde el servidor y esperar respuesta
Claro la fila superior de la pantalla
Mostrar el tweet a través de la fila superior de la pantalla a una velocidad determinada por el control de velocidad de desplazamiento
Un "pseudocódigo" más completa del código de Arduino:
Initialise LCD Set up constants Create buffer for incoming messages Set up the LCD as 16x2 characters, no autoscroll Display "Zeitgeistometer!\n (c) PKM 2010" on the display Set up the servo and its control pin Turn on the servo, move the servo to the "down" position and turn off again loop: Note the time when starting the loop Write "status\n" to the serial link Await a message on the serial link or for ten seconds to elapse If a new message arrived: Wait to receive entire message Read the message into a buffer Read the first char of the message If the first character is 'T' Set "new tweet" flag Active the servo, raise and deactivate Print the contents of the message to the bottom row of the display Else If the new tweet flag is set Clear the new tweet flag Active the servo, lower and deactivate print "#instructables" to the bottom row of the display Else Print "No status message" to the display Wait 0.5 seconds Write "tweet\n" to the serial link Await a message on the serial link or for eight seconds to elapse If a new message arrived: Wait to receive entire message Read the message into a buffer Set the current position to character 0 While the character 15 characters beyond the current position is not a null Read the speed control Map [0-1023] to a delay in the range [50-550]ms, wait for that interval Display the 16 characters from the current position on the top row of the LCD Increment the current position Else Print "No twit response" to the display Function clear_buffer: Write 150 null characters to the message buffer Function read_to_buffer: clear_buffer() while characters are available from the serial link read a character from Serial to the message buffer
Os he adjunto el código fuente real a este paso como un archivo de texto, en parte porque es desordenado y no muy explica por sí mismo así que no lo mejor para leer para tener una idea de cómo funciona el sistema.