Some old AVR projects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.4 KiB

10 years ago
#include <avr/io.h>
#include <util/delay.h>
#include <stdbool.h>
#include <stdint.h>
#include "lib/meta.h"
#include "lib/arduino_pins.h"
#include "lib/calc.h"
#include "lib/colors.h"
#include "lib/ws2812.h"
10 years ago
#define WS1 D8
#define WS2 D9
10 years ago
void SECTION(".init8") init_io()
10 years ago
{
as_output(WS1);
as_output(WS2);
10 years ago
}
void main()
{
const uint8_t anim_step = 10;
const uint8_t anim_max = 250;
const uint8_t pixel_count = 30;
10 years ago
xrgb_t color = xrgb(anim_max, 0, 0);
10 years ago
uint8_t step = 0;
xrgb_t color2 = xrgb(anim_max, 0, 0);
10 years ago
uint8_t step2 = 0;
while (1) {
color = color2;
10 years ago
step = step2;
for (uint8_t i = 0; i < pixel_count; i++) {
ws_send_xrgb(WS1, color);
10 years ago
if (i == 1) {
color2 = color;
10 years ago
step2 = step;
}
switch (step) {
case 0:
color.g += anim_step;
if (color.g >= anim_max) step++;
10 years ago
break;
case 1:
color.r -= anim_step;
if (color.r == 0) step++;
10 years ago
break;
case 2:
color.b += anim_step;
if (color.b >= anim_max) step++;
10 years ago
break;
case 3:
color.g -= anim_step;
if (color.g == 0) step++;
10 years ago
break;
case 4:
color.r += anim_step;
if (color.r >= anim_max) step++;
10 years ago
break;
default:
color.b -= anim_step;
if (color.b == 0) step = 0;
10 years ago
break;
}
}
ws_show();
_delay_ms(20);
10 years ago
}
}