55 lines
929 B
C
55 lines
929 B
C
#include <math.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
|
|
#include "../include/ws2801.h"
|
|
#include "../include/logger.h"
|
|
|
|
#define PI 3.141592654f
|
|
|
|
void set_all(uint8_t r, uint8_t g, uint8_t b)
|
|
{
|
|
for(uint8_t i = 0; i < 20; i++) {
|
|
ws2801_set_colour(i, r, g, b);
|
|
}
|
|
}
|
|
|
|
float sin_off(float phase)
|
|
{
|
|
return 255 * (0.5f + 0.5f * sin(phase));
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
float phase = 0;
|
|
|
|
logger_init();
|
|
|
|
if(ws2801_init(20) == -1) {
|
|
LOG(LVL_FATAL, "Could not initialize WS2801 library.");
|
|
return 1;
|
|
}
|
|
|
|
|
|
while(1) {
|
|
//phase += PI/1000;
|
|
|
|
for(uint8_t i = 0; i < 20; i++) {
|
|
ws2801_set_colour(i, sin_off(i * PI / 10 + phase), sin_off(i * PI / 10 + 1.241*phase), sin_off(i * PI / 10 + 1.537*phase));
|
|
}
|
|
|
|
ws2801_send_update();
|
|
|
|
static const struct timespec sleepval = {0, 40000000};
|
|
nanosleep(&sleepval, NULL);
|
|
}
|
|
|
|
ws2801_shutdown();
|
|
|
|
return 0;
|
|
}
|