Reddit TodayILearned LCD Display
This device is a device that takes the top headline from r/todayilearned and scrolls it across a TextLCD module. This process repeats each time the headline finishes scrolling. As a result, the display is always updated with the top headline
List of mbed components and peripherals used
Ethernet (RJ-45 jack on a breakout board) Mbed Chip Solderless Breadboard LCD Display
main.cpp
#include "mbed.h"
#include "EthernetInterface.h"
#include "TextLCD.h"
#include "HTTPClient.h"
TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d0-d3
DigitalOut led3(LED3); // use for debug
HTTPClient http;
int main() {
int connection;
lcd.cls();
lcd.printf("net setup");
EthernetInterface eth;
eth.init(); //Use DHCP
connection = eth.connect(60000);
if (connection != 0) {
lcd.cls();
lcd.printf("No Connection");
}
char buffer[300];
int ret = http.get("http://www.reddit.com/r/todayilearned/hot.xml?limit=1", buffer, 1000);
lcd.cls();
if (ret == 0) {
lcd.printf("Success!");
} else {
lcd.printf("Failed");
}
char *tstartXML = "<item><title>"; //XML beginning of string
char *tendXML ="</title><link>"; //XML end of string
char *tsptr;
char *teptr;
int i=0,j=0;
printf(buffer);
while (true) {
tsptr = buffer;
tsptr = strstr(tsptr,tstartXML); // find <title> in string - NULL if not
teptr = strstr(tsptr,tendXML); // find <\title> in string - NULL if not
if (tsptr!=NULL) tsptr = tsptr + strlen(tstartXML);// move to char after "<title>"
if ((tsptr!=NULL)&&(teptr!=NULL)) {
led3 = 1;
i=0;
// loop to scroll characters slowly across LCD
for (j=0; (j+15)<(strlen(tsptr)-strlen(teptr)); j++) {
lcd.cls(); // clear screen before writing a new line
// loop to output a line on the LCD
for (i=0; ((i<16)&&(tsptr[i+j-1] != '<')); i++) {
lcd.putc(tsptr[i+j]);
}
if (j==0) wait(1.2); //add first line delays for scroll timing
wait(.2); //delay for charcter scroll timing
}
wait(.4);
//lcd.cls(); //clear LCD between news items
wait(.2);
} else {
}
if (ret < 0) {
break;
}
}
eth.disconnect();
}
Please log in to post comments.
