pimoroni-pico/examples/pico_unicorn/demo.cpp

60 wiersze
1.3 KiB
C++
Czysty Zwykły widok Historia

2021-01-15 16:19:15 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "pico/stdlib.h"
2021-01-16 15:18:39 +00:00
#include "pico_unicorn.hpp"
2021-01-15 16:19:15 +00:00
2021-01-16 15:18:39 +00:00
using namespace pimoroni;
2021-01-15 16:19:15 +00:00
2021-01-16 15:18:39 +00:00
PicoUnicorn pico_unicorn;
2021-01-15 16:19:15 +00:00
void from_hsv(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b) {
float i = floor(h * 6.0f);
float f = h * 6.0f - i;
v *= 255.0f;
uint8_t p = v * (1.0f - s);
uint8_t q = v * (1.0f - f * s);
uint8_t t = v * (1.0f - (1.0f - f) * s);
switch (int(i) % 6) {
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
case 5: r = v; g = p; b = q; break;
}
}
int main() {
2021-01-16 15:18:39 +00:00
pico_unicorn.init();
2021-01-15 16:19:15 +00:00
uint32_t i = 0;
while(true) {
i = i + 1;
uint8_t j = 0;
for(uint8_t y = 0; y < 7; y++) {
for(uint8_t x = 0; x < 16; x++) {
uint8_t r, g, b;
float h = float(x) / 63.0f + float(i) / 500.0f;
h = h - float(int(h));
float s = 1.0f;//(sin(float(i) / 200.0f) * 0.5f) + 0.5f;
float v = (float(y) / 8.0f) + 0.05f;
from_hsv(h, s, v, r, g, b);
2021-01-16 15:18:39 +00:00
pico_unicorn.set_pixel(x, y, r, g, b);
2021-01-15 16:19:15 +00:00
j = j + 1;
}
}
2021-01-16 15:18:39 +00:00
pico_unicorn.update();
2021-01-15 16:19:15 +00:00
}
printf("done\n");
return 0;
}