2014-09-11 06:26:28 +00:00
|
|
|
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2014-09-06 22:52:27 +00:00
|
|
|
// Small example how to use the library.
|
|
|
|
|
// For more examples, look at demo-main.cc
|
|
|
|
|
//
|
2014-09-12 03:03:56 +00:00
|
|
|
// This code is public domain
|
|
|
|
|
// (but note, that the led-matrix library this depends on is GPL v2)
|
|
|
|
|
|
2014-09-06 22:14:53 +00:00
|
|
|
#include "led-matrix.h"
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2014-09-06 22:52:27 +00:00
|
|
|
#include <math.h>
|
2014-09-11 04:52:45 +00:00
|
|
|
#include <stdio.h>
|
2016-08-21 03:45:41 +00:00
|
|
|
#include <signal.h>
|
2014-09-06 22:14:53 +00:00
|
|
|
|
|
|
|
|
using rgb_matrix::GPIO;
|
|
|
|
|
using rgb_matrix::RGBMatrix;
|
|
|
|
|
using rgb_matrix::Canvas;
|
|
|
|
|
|
2016-08-21 03:45:41 +00:00
|
|
|
volatile bool interrupt_received = false;
|
|
|
|
|
static void InterruptHandler(int signo) {
|
|
|
|
|
interrupt_received = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-06 22:52:27 +00:00
|
|
|
static void DrawOnCanvas(Canvas *canvas) {
|
2014-09-11 07:05:52 +00:00
|
|
|
/*
|
|
|
|
|
* Let's create a simple animation. We use the canvas to draw
|
|
|
|
|
* pixels. We wait between each step to have a slower animation.
|
|
|
|
|
*/
|
|
|
|
|
canvas->Fill(0, 0, 255);
|
|
|
|
|
|
|
|
|
|
int center_x = canvas->width() / 2;
|
|
|
|
|
int center_y = canvas->height() / 2;
|
|
|
|
|
float radius_max = canvas->width() / 2;
|
|
|
|
|
float angle_step = 1.0 / 360;
|
|
|
|
|
for (float a = 0, r = 0; r < radius_max; a += angle_step, r += angle_step) {
|
2016-08-21 03:45:41 +00:00
|
|
|
if (interrupt_received)
|
|
|
|
|
return;
|
2014-09-11 07:05:52 +00:00
|
|
|
float dot_x = cos(a * 2 * M_PI) * r;
|
|
|
|
|
float dot_y = sin(a * 2 * M_PI) * r;
|
|
|
|
|
canvas->SetPixel(center_x + dot_x, center_y + dot_y,
|
|
|
|
|
255, 0, 0);
|
|
|
|
|
usleep(1 * 1000); // wait a little to slow down things.
|
|
|
|
|
}
|
2014-09-06 22:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-06 22:14:53 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2016-08-22 03:01:51 +00:00
|
|
|
RGBMatrix::Options defaults;
|
2016-09-17 02:02:53 +00:00
|
|
|
defaults.hardware_mapping = "regular"; // or e.g. "adafruit-hat"
|
2016-08-22 03:01:51 +00:00
|
|
|
defaults.rows = 32;
|
|
|
|
|
defaults.chain_length = 1;
|
|
|
|
|
defaults.parallel = 1;
|
|
|
|
|
defaults.show_refresh_rate = true;
|
|
|
|
|
Canvas *canvas = rgb_matrix::CreateMatrixFromFlags(&argc, &argv, &defaults);
|
2016-08-21 02:26:20 +00:00
|
|
|
if (canvas == NULL)
|
2014-09-11 07:05:52 +00:00
|
|
|
return 1;
|
2016-08-20 18:10:32 +00:00
|
|
|
|
2016-08-21 03:45:41 +00:00
|
|
|
// It is always good to set up a signal handler to cleanly exit when we
|
|
|
|
|
// receive a CTRL-C for instance. The DrawOnCanvas() routine is looking
|
|
|
|
|
// for that.
|
|
|
|
|
signal(SIGTERM, InterruptHandler);
|
|
|
|
|
signal(SIGINT, InterruptHandler);
|
|
|
|
|
|
2014-09-11 07:05:52 +00:00
|
|
|
DrawOnCanvas(canvas); // Using the canvas.
|
2014-09-06 22:14:53 +00:00
|
|
|
|
2014-09-11 07:05:52 +00:00
|
|
|
// Animation finished. Shut down the RGB matrix.
|
|
|
|
|
canvas->Clear();
|
|
|
|
|
delete canvas;
|
2014-09-06 22:14:53 +00:00
|
|
|
|
2014-09-11 07:05:52 +00:00
|
|
|
return 0;
|
2014-09-06 22:14:53 +00:00
|
|
|
}
|