Instructables

An Arduino RSS Feed Display

Featured

Step 4: The Arduino Code

// This code is for the Arduino RSS feed project, by Fritter
// Read the comment lines to figure out how it works

int startstring = 0;     // recognition of beginning of new string
int charcount = 0;     // keeps track of total chars on screen
       
#include  <LiquidCrystal.h>  // import the LiquidCrystal Library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
         Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
         lcd.begin(16,2);            // Initialize the LCD size 16x2. Change if using a larger LCD
         lcd.setCursor(0,0);     // Set cursor position to top left corner
         pinMode(13, OUTPUT);
}

void loop() {
        char incomingByte = 0;   // for incoming serial data
       
         if (Serial.available() > 0) {        // Check for incoming Serial Data
                 digitalWrite(13, HIGH);
                 incomingByte = Serial.read();
                 if ((incomingByte == '~') && (startstring == 1)){            // Check for the closing '~' to end the printing of serial data      
                   startstring = 0;                                                                  // Set the printing to off
                   delay(5000);                                                                     // Wait 5 seconds
                   lcd.clear();                                                                         // Wipe the screen
                   charcount = 0;                                                                   // reset the character count to 0
                   lcd.setCursor(0,0);                                                          // reset the cursor to 0,0
                 }
                 if (startstring == 1){                                                             // check if the string has begun if first '~' has been read
                   if (charcount <= 30){                                                        // check if charcount is under or equal to 30
                     lcd.print(incomingByte);                                                // Print the current byte in the serial
                     charcount = charcount++;                                             // Increment the charcount by 1 yes I know it's awkward
                     }
                   }
                   if (charcount == 31){                                                         // if the charcount is equal to 31 aka the screen is full
                     delay(500);
                     lcd.clear();                                                                        // clear the screen
                     lcd.setCursor(0,0);                                                         // set cursor to 0,0
                     lcd.print(incomingByte);                                                // continue printing data
                     charcount = 1;                                                                 // set charcount back to 1
                   }
                  
                 if (incomingByte == '~'){                                                    // Check if byte is marker ~ to start the printing
                  
                   startstring = 1;                                                                  // start printing
                 }
         }
                 digitalWrite(13, LOW);
                 delay(10);                                                                            // 10ms delay for stability
             } 
 
Remove these adsRemove these ads by Signing Up
brndnlstr1 year ago
I could be wrong, but charcount=charcount++; won't do anything.

If you want to increment, you only need this:

charcount++;

That will increment by one.
fritterdonut (author)  brndnlstr1 year ago
It will in fact add 1 to the total, but it is redundant.

the ++ modifier essentially acts as variable = variable + 1

So in this case it says variable = variable = variable + 1

It works, but should simply say charcount++ for the sake of simplicity and easier reading. Thanks for pointing it out.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!