Skip to content

Commit f8f76c1

Browse files
committed
Add backlight implementation
1 parent c55de79 commit f8f76c1

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

src/GigaDisplayRGB.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)