tetris-clock/src/main.cpp
2023-05-25 18:36:34 +02:00

64 lines
2.5 KiB
C++

#include <Arduino.h>
#include <configuration.h>
#include <Adafruit_Protomatter.h>
uint8_t rgbPins[] = {PIN_LED_R1, PIN_LED_G1, PIN_LED_B1,
PIN_LED_R2, PIN_LED_G2, PIN_LED_B2};
uint8_t addrPins[] = {PIN_LED_A, PIN_LED_B, PIN_LED_C, PIN_LED_D};
uint8_t clockPin = PIN_LED_CLK;
uint8_t latchPin = PIN_LED_STB;
uint8_t oePin = PIN_LED_OE;
Adafruit_Protomatter matrix(
64, // Width of matrix (or matrix chain) in pixels
4, // Bit depth, 1-6
1, rgbPins, // # of matrix chains, array of 6 RGB pins for each
4, addrPins, // # of address pins (height is inferred), array of pins
clockPin, latchPin, oePin, // Other matrix control pins
false); // No double-buffering here (see "doublebuffer" example)
void setup(void) {
Serial.begin(115200);
// Initialize matrix...
ProtomatterStatus status = matrix.begin();
Serial.print("Protomatter begin() status: ");
Serial.println((int)status);
if(status != PROTOMATTER_OK) {
// DO NOT CONTINUE if matrix setup encountered an error.
for(;;);
}
// Since this is a simple program with no animation, all the
// drawing can be done here in setup() rather than loop():
// Make four color bars (red, green, blue, white) with brightness ramp:
for(int x=0; x<matrix.width(); x++) {
uint8_t level = x * 256 / matrix.width(); // 0-255 brightness
matrix.drawPixel(x, matrix.height() - 4, matrix.color565(level, 0, 0));
matrix.drawPixel(x, matrix.height() - 3, matrix.color565(0, level, 0));
matrix.drawPixel(x, matrix.height() - 2, matrix.color565(0, 0, level));
matrix.drawPixel(x, matrix.height() - 1,
matrix.color565(level, level, level));
}
// You'll notice the ramp looks smoother as bit depth increases
// (second argument to the matrix constructor call above setup()).
// Simple shapes and text, showing GFX library calls:
matrix.drawCircle(12, 10, 9, matrix.color565(255, 0, 0));
matrix.drawRect(14, 6, 17, 17, matrix.color565(0, 255, 0));
matrix.drawTriangle(32, 9, 41, 27, 23, 27, matrix.color565(0, 0, 255));
matrix.println("ADAFRUIT"); // Default text color is white
if (matrix.height() > 32) {
matrix.setCursor(0, 32);
matrix.println("64 pixel"); // Default text color is white
matrix.println("matrix"); // Default text color is white
}
matrix.show(); // Copy data to matrix buffers
}
void loop(void) {
Serial.print("Refresh FPS = ~");
Serial.println(matrix.getFrameCount());
delay(1000);
}