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.
100 lines
1.7 KiB
100 lines
1.7 KiB
2 years ago
|
#include <util/delay.h>
|
||
|
#include "iopins.h"
|
||
|
#include "color.h"
|
||
|
#include "wsrgb.h"
|
||
|
|
||
|
#define BUTTON1 D6
|
||
|
#define BUTTON2 D7
|
||
|
#define BUZZER D10
|
||
|
#define BLINK D13
|
||
|
|
||
|
void beep(uint8_t tone) {
|
||
|
for (uint16_t i = 0; i < 50; i++) {
|
||
|
toggle_pin(BUZZER);
|
||
|
for(int j = 0; j < tone; j++) {
|
||
|
_delay_us(10);
|
||
|
}
|
||
|
toggle_pin(BUZZER);
|
||
|
for(int j = 0; j < tone; j++) {
|
||
|
_delay_us(10);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
xrgb_t colors[30];
|
||
|
|
||
|
void clear_strip() {
|
||
|
for (int i = 0; i < 30; i++) {
|
||
|
colors[i].r = 0;
|
||
|
colors[i].g = 0;
|
||
|
colors[i].b = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
// Buttons
|
||
|
as_input_pu(BUTTON1);
|
||
|
as_input_pu(BUTTON2);
|
||
|
|
||
|
// Buzzer
|
||
|
as_output(BUZZER);
|
||
|
|
||
|
// Neopixels
|
||
|
ws_init();
|
||
|
|
||
|
|
||
|
clear_strip();
|
||
|
|
||
|
hsl_t cursor = {
|
||
|
.h = 0,
|
||
|
.s = 255,
|
||
|
.l = 255,
|
||
|
};
|
||
|
|
||
|
int8_t dir = 1;
|
||
|
|
||
|
int cnt = 0;
|
||
|
while (1) {
|
||
|
if (cnt++ == 15) {
|
||
|
toggle_pin(BLINK);
|
||
|
cnt = 0;
|
||
|
}
|
||
|
|
||
|
if (is_low(BUTTON1)) {
|
||
|
if (dir != 1) {
|
||
|
dir = 1;
|
||
|
beep(80);
|
||
|
clear_strip();
|
||
|
}
|
||
|
} else if (is_low(BUTTON2)) {
|
||
|
if (dir != 8) {
|
||
|
dir = 8;
|
||
|
beep(50);
|
||
|
clear_strip();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
cursor.h = (uint8_t) ((int8_t)cursor.h + dir);
|
||
|
|
||
|
// shift all
|
||
|
for (int i = 29; i >= 1; i--) {
|
||
|
colors[i] = colors[i - 1];
|
||
|
}
|
||
|
|
||
|
// set first
|
||
|
colors[0] = hsl_xrgb(cursor);
|
||
|
|
||
|
|
||
|
// show
|
||
|
for (int i = 0; i < 30; i++) {
|
||
|
ws_send_xrgb(colors[i]);
|
||
|
}
|
||
|
ws_show();
|
||
|
|
||
|
_delay_ms(25);
|
||
|
|
||
|
}
|
||
|
}
|