-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled_controller_sample.cc
More file actions
68 lines (55 loc) · 1.87 KB
/
Copy pathled_controller_sample.cc
File metadata and controls
68 lines (55 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* ---------------------------------------------------------------------------
** This software is in the public domain, furnished "as is", without technical
** support, and with no warranty, express or implied, as to its usefulness for
** any purpose. You are free to modify it and use it in any way you want,
** but you have to leave this header intact.
**
**
** led_controller_sample.cc
** A simple test app, that lights 4 LEDs of the ReSpeaker 4mic_hat using the
** LedController class
**
** Author: Oliver Pahl
** -------------------------------------------------------------------------*/
#include "led_controller.h"
#include <unistd.h>
#include <cstdlib>
#include <new>
#include <signal.h>
#define NUMBER_OF_LEDS 12
#define MAX_BRIGHTNESS 31
// Interruption Signal Handler, so we clean up after Ctrl+C
void IntSignalHandler(int sig) {
LedController *led_controller = &LedController::GetInstance();
led_controller->PowerDown();
exit(0);
}
int main() {
// Install the signal handler
signal(SIGINT, IntSignalHandler);
// Initialize the Controller
LedController *led_controller = &LedController::GetInstance();
led_controller->PowerUp(NUMBER_OF_LEDS);
// Rotating the LEDs one time
for(int i = 0; i <= NUMBER_OF_LEDS; i++)
{
// Clear the LEDs
led_controller->Clear();
// Set a few pixel to test
// Red
led_controller->SetPixelColor(i % NUMBER_OF_LEDS, 24, 0, 0, MAX_BRIGHTNESS);
// Green
led_controller->SetPixelColor((i + 3) % NUMBER_OF_LEDS, 0, 24, 0, MAX_BRIGHTNESS);
// Blue
led_controller->SetPixelColor((i + 6) % NUMBER_OF_LEDS, 0, 0, 24, MAX_BRIGHTNESS);
// White
led_controller->SetPixelColor((i + 9) % NUMBER_OF_LEDS, 12, 12, 12, MAX_BRIGHTNESS);
// Show the pixels
led_controller->Show();
// Sleep for a few seconds and the clean up
sleep(1);
}
// Shutdown
led_controller->PowerDown();
return 0;
}