Stap 3: Firmware
Initialiseren van de LCD
Sommige constanten gebruikt in de code instellen
Afdrukken van een eerste bericht aan het LCD-scherm
Instellen van de servo en verlagen van de vlag
Vijf seconden gewacht tot het script op de server PC worden opgestart
Lus:
Verzoekstatus van server en wacht op antwoord
Als nieuwe tweets: verhogen van de vlag en het aantal tweets weergeven
anders: verlagen van de vlag en de hashtag zoeken weergeven
Volgende tweet aanvragen bij de server en wacht op antwoord
De bovenste rij van het display wissen
De tweet scrollen in de bovenste rij van het display een tempo bepaald door de controle van de snelheid weergeven
Een meer complete "pseudocode" van de Arduino-code:
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
Ik heb de werkelijke broncode gekoppeld aan deze stap als een tekstbestand, deels omdat het rommelig en niet zeer spreekt voor zich dus niet het beste ding om te lezen om te krijgen een idee van hoe het systeem werkt.