Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Minimal library for controlling the built-in RGB on the GIGA Display Shield via
To use this library:

```
#include <Arduino_GigaDisplayRGB.h>
#include <Arduino_GigaDisplay.h>
```


Minimal example:

```
#include <Arduino_GigaDisplayRGB.h>
#include <Arduino_GigaDisplay.h>

GigaDisplayRGB rgb;

Expand Down
20 changes: 20 additions & 0 deletions examples/backlight/SimpleBacklight/SimpleBacklight.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Changes the display backlight from very dim to 100%
This example code is in the public domain.
*/

#include <Arduino_GigaDisplay.h>

//Create backlight object
GigaDisplayBacklight backlight;

void setup() {
//init library
backlight.begin();
}

int i = 0;
void loop() {
backlight.set(i++ % 100);
delay(100);
}
2 changes: 1 addition & 1 deletion examples/rgb/SimpleRGB/SimpleRGB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
This example code is in the public domain.
*/

#include <Arduino_GigaDisplayRGB.h>
#include <Arduino_GigaDisplay.h>

//Create rgb object
GigaDisplayRGB rgb;
Expand Down
2 changes: 1 addition & 1 deletion examples/rgb/blink/blink.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
This example code is in the public domain.
*/

#include <Arduino_GigaDisplayRGB.h>
#include <Arduino_GigaDisplay.h>

//Create rgb object
GigaDisplayRGB rgb;
Expand Down
37 changes: 37 additions & 0 deletions src/GigaDisplayRGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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