Skip to content

Commit c5ac8d2

Browse files
authored
Merge pull request #10 from arduino-libraries/backlight
Add backlight implementation (and fix some includes in the meantime)
2 parents de25be3 + f8f76c1 commit c5ac8d2

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

docs/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Minimal library for controlling the built-in RGB on the GIGA Display Shield via
55
To use this library:
66

77
```
8-
#include <Arduino_GigaDisplayRGB.h>
8+
#include <Arduino_GigaDisplay.h>
99
```
1010

1111

1212
Minimal example:
1313

1414
```
15-
#include <Arduino_GigaDisplayRGB.h>
15+
#include <Arduino_GigaDisplay.h>
1616
1717
GigaDisplayRGB rgb;
1818
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+
}

examples/rgb/SimpleRGB/SimpleRGB.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
1414
GigaDisplayRGB rgb;

examples/rgb/blink/blink.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
1414
GigaDisplayRGB rgb;

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)