File tree Expand file tree Collapse file tree 5 files changed +61
-4
lines changed
backlight/SimpleBacklight Expand file tree Collapse file tree 5 files changed +61
-4
lines changed Original file line number Diff line number Diff line change @@ -5,14 +5,14 @@ Minimal library for controlling the built-in RGB on the GIGA Display Shield via
55To use this library:
66
77```
8- #include <Arduino_GigaDisplayRGB .h>
8+ #include <Arduino_GigaDisplay .h>
99```
1010
1111
1212Minimal example:
1313
1414```
15- #include <Arduino_GigaDisplayRGB .h>
15+ #include <Arduino_GigaDisplay .h>
1616
1717GigaDisplayRGB rgb;
1818
Original file line number Diff line number Diff line change 1+ /*
2+ Changes the display backlight from very dim to 100%
3+ This example code is in the public domain.
4+ */
5+
6+ #include < Arduino_GigaDisplay.h>
7+
8+ // Create backlight object
9+ GigaDisplayBacklight backlight;
10+
11+ void setup () {
12+ // init library
13+ backlight.begin ();
14+ }
15+
16+ int i = 0 ;
17+ void loop () {
18+ backlight.set (i++ % 100 );
19+ delay (100 );
20+ }
Original file line number Diff line number Diff line change 88 This example code is in the public domain.
99*/
1010
11- #include < Arduino_GigaDisplayRGB .h>
11+ #include < Arduino_GigaDisplay .h>
1212
1313// Create rgb object
1414GigaDisplayRGB rgb;
Original file line number Diff line number Diff line change 88 This example code is in the public domain.
99*/
1010
11- #include < Arduino_GigaDisplayRGB .h>
11+ #include < Arduino_GigaDisplay .h>
1212
1313// Create rgb object
1414GigaDisplayRGB rgb;
Original file line number Diff line number Diff line change @@ -13,4 +13,41 @@ class GigaDisplayRGB {
1313 void writeByte (uint8_t ,uint8_t );
1414};
1515
16+ #include " mbed.h"
17+ using namespace std ::chrono_literals;
18+ using namespace std ::chrono;
19+
20+ class GigaDisplayBacklight {
21+ public:
22+ GigaDisplayBacklight () {}
23+ void begin (int target_percent = 100 ) {
24+ pin = new mbed::DigitalOut (PB_12);
25+ ticker = new mbed::Ticker ();
26+ ticker->attach (mbed::callback (this , &GigaDisplayBacklight::cb), 2ms);
27+ set (target_percent);
28+ }
29+ void cb () {
30+ static int counter = 0 ;
31+ if (counter > intensity) {
32+ *pin = 0 ;
33+ } else {
34+ *pin = 1 ;
35+ }
36+ counter += 10 ;
37+ if (counter == 100 ) {
38+ counter = 0 ;
39+ }
40+ }
41+ void set (int target_percent) {
42+ intensity = target_percent;
43+ }
44+ void off () {
45+ set (0 );
46+ }
47+ private:
48+ mbed::Ticker* ticker;
49+ mbed::DigitalOut* pin;
50+ int intensity;
51+ };
52+
1653#endif
You can’t perform that action at this time.
0 commit comments