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;
}

View File

@ -24,10 +24,22 @@
#include "jhd1313m1.h"
#include "upm_utilities.h"
#include "signal.h"
#include "string.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
//! [Interesting]
signal(SIGINT, sig_handler);
//! [Interesting]
// initialize a JHD1313m1 on I2C bus 0, LCD address 0x3e, RGB
// address 0x62
jhd1313m1_context lcd = jhd1313m1_init(0, 0x3e, 0x62);
@ -38,18 +50,32 @@ int main(int argc, char **argv)
return 1;
}
jhd1313m1_set_cursor(lcd, 0, 0);
jhd1313m1_write(lcd, "Hello World 1", 13);
int ndx = 0;
char str[20];
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)
{
snprintf(str, sizeof(str), "Hello World %d", ndx);
// Alternate rows on the LCD
jhd1313m1_set_cursor(lcd, ndx%2, 0);
jhd1313m1_write(lcd, str, strlen(str));
// Change the color
uint8_t r = rgb[ndx%7][0];
uint8_t g = rgb[ndx%7][1];
uint8_t b = rgb[ndx%7][2];
jhd1313m1_set_color(lcd, r, g, b);
// Echo via printf
printf("Hello World %d rgb: 0x%02x%02x%02x\n", ndx++, r, g, b);
upm_delay(3);
// change background color to a dimmer pure green
jhd1313m1_set_color(lcd, 0, 128, 0);
jhd1313m1_set_cursor(lcd, 1, 0);
jhd1313m1_write(lcd, "Hello World 2", 13);
upm_delay(3);
upm_delay(1);
}
jhd1313m1_close(lcd);
//! [Interesting]