diff --git a/docs/readme.md b/docs/readme.md index 3c981ad..8cdb161 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -5,14 +5,14 @@ Minimal library for controlling the built-in RGB on the GIGA Display Shield via To use this library: ``` -#include +#include ``` Minimal example: ``` -#include +#include GigaDisplayRGB rgb; diff --git a/examples/backlight/SimpleBacklight/SimpleBacklight.ino b/examples/backlight/SimpleBacklight/SimpleBacklight.ino new file mode 100644 index 0000000..922ed51 --- /dev/null +++ b/examples/backlight/SimpleBacklight/SimpleBacklight.ino @@ -0,0 +1,20 @@ +/* + Changes the display backlight from very dim to 100% + This example code is in the public domain. +*/ + +#include + +//Create backlight object +GigaDisplayBacklight backlight; + +void setup() { + //init library + backlight.begin(); +} + +int i = 0; +void loop() { + backlight.set(i++ % 100); + delay(100); +} diff --git a/examples/rgb/SimpleRGB/SimpleRGB.ino b/examples/rgb/SimpleRGB/SimpleRGB.ino index c43ff12..7cc9dea 100644 --- a/examples/rgb/SimpleRGB/SimpleRGB.ino +++ b/examples/rgb/SimpleRGB/SimpleRGB.ino @@ -8,7 +8,7 @@ This example code is in the public domain. */ -#include +#include //Create rgb object GigaDisplayRGB rgb; diff --git a/examples/rgb/blink/blink.ino b/examples/rgb/blink/blink.ino index 1b310b4..7fd2028 100644 --- a/examples/rgb/blink/blink.ino +++ b/examples/rgb/blink/blink.ino @@ -8,7 +8,7 @@ This example code is in the public domain. */ -#include +#include //Create rgb object GigaDisplayRGB rgb; diff --git a/src/GigaDisplayRGB.h b/src/GigaDisplayRGB.h index cb3457f..129c47c 100644 --- a/src/GigaDisplayRGB.h +++ b/src/GigaDisplayRGB.h @@ -13,4 +13,41 @@ class GigaDisplayRGB { void writeByte(uint8_t,uint8_t); }; +#include "mbed.h" +using namespace std::chrono_literals; +using namespace std::chrono; + +class GigaDisplayBacklight { + public: + GigaDisplayBacklight() {} + void begin(int target_percent = 100) { + pin = new mbed::DigitalOut(PB_12); + ticker = new mbed::Ticker(); + ticker->attach(mbed::callback(this, &GigaDisplayBacklight::cb), 2ms); + set(target_percent); + } + void cb() { + static int counter = 0; + if (counter > intensity) { + *pin = 0; + } else { + *pin = 1; + } + counter += 10; + if (counter == 100) { + counter = 0; + } + } + void set(int target_percent) { + intensity = target_percent; + } + void off() { + set(0); + } + private: + mbed::Ticker* ticker; + mbed::DigitalOut* pin; + int intensity; +}; + #endif \ No newline at end of file