Étape 3: Firmware
Initialiser l’écran LCD
Mettre en place certaines constantes utilisées dans le code
Imprimer un message initial à l’écran LCD
Mettre en place le servo et abaisser le drapeau
Attendez cinq secondes pour le script pour être lancé sur le PC serveur
Boucle :
Demande de statut du serveur et attendre la réponse
Si nouveaux tweets : hisser le drapeau et afficher le nombre de tweets
autre chose : abaisser le drapeau et afficher le hashtag de recherche
Demande le prochain tweet du serveur et attendre la réponse
Effacer la ligne supérieure de l’écran
Afficher le tweet sur la rangée supérieure de l’écran à une vitesse déterminée par le contrôle de la vitesse de défilement
Un « pseudo-code » plus complète du code de l’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
J’ai joint le code source réelle à cette étape comme un fichier texte, en partie parce que c’est salissant et pas très explicite afin de ne pas la meilleure chose à lire pour avoir une idée du fonctionnement du système.