Internet Of Things Sensors
  • Cover
  • Summary
  • About This Training
    • Objectives
    • Skills
    • Prerequisites
    • Requirements
  • Once Upon a Time ...
  • Introduction
    • Topologies
    • Data Compression
  • Communication Protocols
    • I2C
      • Linux
      • Arduino
    • Serial Peripheral Interface
    • Serial Communication
      • Laboratory
        • Arduino and Linux
    • Infrared
    • Pulse Width Modulation
  • Microsystems Technologies
    • Actuators
    • Sensors
    • Transducers
  • Layers of Abstraction
    • IntelĀ® IoT Developer Kit Libraries
      • MRAA
      • UPM
      • Laboratory
      • Contributions
    • Linux I2C Device Interface
      • LCD RGB Color Display
      • LCD RGB Text
      • LCD RGB Display Off
      • Temperature
    • Linux I2C Subsystem
  • Data Engines
    • Sparkfun
  • Wrap-Up
    • Online Training
    • Challenge
  • References
  • Sandbox
Powered by GitBook
On this page
  1. Layers of Abstraction
  2. Linux I2C Device Interface

LCD RGB Color Display

Once your code is working lets add a method to init our RGB controller, also we will need a method to set the color of the Display :

void setRGBColor(I2CCONTEXT *rgb, int r, int g, int b)
{
        writeByteRegister(rgb->file, REG_RED, r);
        writeByteRegister(rgb->file, REG_GREEN, g);
        writeByteRegister(rgb->file, REG_BLUE, b);            
}
void initRGB(I2CCONTEXT *rgb)
{
        // backlight init
        writeByteRegister(rgb->file, REG_MODE1, 0);
        // set LEDs controllable by both PWM and GRPPWM registers
        writeByteRegister(rgb->file, REG_OUTPUT, 0xFF);
        // set MODE2 values
        writeByteRegister(rgb->file, REG_MODE2, 0x20);
        // set the baklight Color to white :)
        setRGBColor(rgb, 0xFF, 0xFF, 0xFF);    
}

Add another method to turn off the light upon program exit:

void turnOffRGB(I2CCONTEXT *rgb)
{
    setRGBColor(rgb, 0x00, 0x00, 0x00);    
}

Now lets call init RGB from our main() by passing the reference to our RGB context wait about 5 seconds and then exit turning off the color leds:

/*turn on RGB LEDS*/
initRGB(&rgb);
/*sleep for 5 secs before turning off*/
sleep(5);
/*turn off RGB LEDS*/
turnOffRGB(&rgb);

run make clean then make and execute by typing ./lcdtest

root@edison:~/.../I2CDL# make clean
rm lcd
root@edison:~/.../I2CDL# make
gcc -O lcd.c -o lcdtest
root@edison:~/.../I2CDL# ./lcdtest

DONE!
PreviousLinux I2C Device InterfaceNextLCD RGB Text

Last updated 7 years ago