Examples
Simple countdown
Simple countdown example. Counts down from 10 and displays the text “GO!”. Very low network latency is assumed.
<? require_once('LedSign.php'); $ledSign = new LedSign('192.168.0.106'); // change this to ip of your sign for ($i = 10; $i > 0; $i--) { sleep(1); $ledSign->setText($i); } $ledSign->setText('GO!'); ?>
Simple monitoring
Example of monitoring the number of users online on a web site. Updates every 5 seconds.
<? require_once('LedSign.php'); $ledSign = new LedSign('192.168.0.106'); // change this to ip of your sign while (true) { // url to a script that returns the number // of users online in plain text $url = 'http://www.mywebcommunity/api/users-online'; $i = file_get_contents($url); $ledSign->setText($i); sleep(5); } ?>
Digg news feed
The following example shows the topics of the
the 20 first popular articles on digg:
<? require_once('LedSign.php'); $ledSign = new LedSign('192.168.0.106'); // change this to the ip of your sign while (true) { $url = 'http://feeds.digg.com/digg/news/topic/world_news/popular.rss'; $rss = file_get_contents($url); @$feed = new SimpleXMLElement($rss); $text = ""; $count = 0; foreach ($feed->channel->item as $item){ $title = (string)$item->title; $title = LedSign::replaceCurlyBrackets($title); $text = $text . "$title | "; $count++; if ($count > 20){ break; } } $ledSign->setText($text, true); sleep(120); } ?>
It results in this: (sorry about the crappy video quality)
The following example shows 15 last status updates of
ones friends on Facebook:
require_once('LedSign.php'); $ledSign = new LedSign('192.168.0.106'); // change this to the ip of your sign // change this to the address of your friends rss feed // found under "All friends" $feedUrl = 'http://www.facebook.com/feeds/friends_status.php' . '?id=SOME_ID&key=SOME_KEY&format=rss20&flid=0'; while (true) { // Load the rss feed from Facebook // We need to use curl to fake the user agent, because otherwise Facebook // responds with an "unsupported browser" error $ch = curl_init(); $userAgent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; ' . 'fi; rv:1.9.0.4) ' . 'Gecko/2008102920 Firefox/3.0.4'; curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL, $feedUrl); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $rss = curl_exec($ch); curl_close($ch); @$feed = new SimpleXMLElement($rss); $text = "{f0}"; $count = 0; foreach ($feed->channel->item as $item){ $title = (string)$item->title; // handle non-ASCII friends $title = str_replace('ä', 'a', $title); $title = str_replace('Ä', 'A', $title); $title = str_replace('ö', 'o', $title); $title = str_replace('Ö', 'O', $title); $title = LedSign::replaceCurlyBrackets($title); $text = $text . "$title | "; $count++; if ($count > 15){ break; } } $ledSign->setText($text, true); sleep(120); } ?>