jhd1313m1: Added while loop to LCD example c/cxx

Make these just a bit more interesting - continuously change color
and keep updating the lcd.  Also, echo the write via printf.

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-10-26 14:28:54 -07:00
parent c09ab37a59
commit f623414c04
2 changed files with 78 additions and 23 deletions

View File

@ -22,22 +22,51 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <signal.h>
#include "jhd1313m1.hpp"
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int
main(int argc, char **argv)
{
//! [Interesting]
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
lcd->setCursor(0,0);
lcd->write("Hello World");
lcd->setCursor(1,2);
lcd->write("Hello World");
signal(SIGINT, sig_handler);
printf("Sleeping for 5 seconds\n");
sleep(5);
delete lcd;
//! [Interesting]
//! [Interesting]
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
upm::Jhd1313m1 lcd(0, 0x3E, 0x62);
int ndx = 0;
uint8_t rgb[7][3] = {
{0xd1, 0x00, 0x00},
{0xff, 0x66, 0x22},
{0xff, 0xda, 0x21},
{0x33, 0xdd, 0x00},
{0x11, 0x33, 0xcc},
{0x22, 0x00, 0x66},
{0x33, 0x00, 0x44}};
while (shouldRun)
{
// Alternate rows on the LCD
lcd.setCursor(ndx%2,0);
// Change the color
uint8_t r = rgb[ndx%7][0];
uint8_t g = rgb[ndx%7][1];
uint8_t b = rgb[ndx%7][2];
lcd.setColor(r, g, b);
lcd.write("Hello World " + std::to_string(ndx));
// Echo via printf
printf("Hello World %d rgb: 0x%02x%02x%02x\n", ndx++, r, g, b);
sleep(1);
}
//! [Interesting]
return 0;
}