mca-pendel/sketches/djhgfjh/led-driver.c

86 lines
4.6 KiB
C

#include <stdint.h>
#include <stddef.h>
#include <avr/io.h>
//~ #include <avr/pgmspace.h>
#include <stdbool.h>
#include "WS2812B_Atmega.h"
#include "color_hsv.h"
//~ #include "party.h"
#include <stdio.h>
#include "colors.h"
#define LEDS 30
#define HUE_MAX 610 // pink red
#define HUE_MIN 350 // dark blue
#define HUE_STEPS 1
//~ const size_t cols = LEDS;
//~ const size_t rows = (HUE_MAX - HUE_MIN) / (HUE_STEPS * 2);
//~ void init_rgbLookup(rgb_t lut[rows][cols], size_t rows, size_t cols, uint16_t hueMin, uint16_t hueMax, uint16_t steps) {
//~ uint8_t sat = 100, val = 30;
//~ hsv_t colorsHSV[cols];
//~ for( int row = 0; row < rows; row++) {
//~ interpolateLinearly(init_hsv_t(hueMin, sat, val), init_hsv_t(hueMax, sat, val), cols, colorsHSV);
//~ hsv2rgbList(colorsHSV, lut[row],cols);
//~ hueMin += steps;
//~ hueMax -= steps;
//~ }
//~ }
int main(void){
//~ partyHard(LEDS);
//const static uint64_t poo[] = {884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 883, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884, 884};
//~ rgb_t rgbLookup[rows][cols]; // = 11700 Byte
//~ init_rgbLookup(rgbLookup, rows, cols, HUE_MIN, HUE_MAX, HUE_STEPS);
//~ printf("const static uint8_t rgbLookup = {\t// begin matrix\n");
//~ for(int i = 0; i < rows; i++) {
//~ printf("\t{\t// begin row #%d\n", i);
//~ for( int j = 0; j < cols; j++) {
//~ printf("\t\t{%d,%d,%d},\t// col #%d\n", rgbLookup[i][j].r, rgbLookup[i][j].g, rgbLookup[i][j].b, j);
//~ }
//~ printf("\t},\t// end row #%d\n",i);
//~ }
//~ printf("};\t end matrix");
//~ uint64_t test = poo[27] + 3 * poo[10];
//~ test += 5 - poo[12];
DDRC = 0x01; // PORT C0 output
size_t row = 0;
size_t col = 0;
int8_t sign = 1;
while(true) {
if( sign == 1) {
for(col = 0; col < COLS; col++){
writeRGB(rgbTable[row][col][0], rgbTable[row][col][1], rgbTable[row][col][2]);
}
} else if( sign == -1) {
size_t index = COLS - 1 - col;
for(col = 0; col < COLS; col++){
writeRGB(rgbTable[row][index][0], rgbTable[row][index][1], rgbTable[row][index][2]);
}
}
_delay_ms(50);
row += sign;
if(row == ROWS - 1) {
sign = -1;
} else if(row == 0) {
sign = 1;
}
}
}