-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfast_rainbow_test.ino
51 lines (44 loc) · 1.58 KB
/
fast_rainbow_test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// https://github.com/Makuna/NeoPixelBus
// https://github.com/Makuna/NeoPixelBus/wiki/NeoPixelBus-object-API
// https://github.com/Makuna/NeoPixelBus/wiki/HslColor-object-API
// http://www.vagrearg.org/content/hsvrgb
#include <NeoPixelBus.h>
//#define HSV_USE_ASSEMBLY /* Optimize code using assembly */
// If assembly is used, Arduino IDE must be modified!:
// C:\Program Files (x86)\Arduino\hardware\arduino\avr\platform.txt
// compiler.cpp.flags: -OS -> -O1
#include "fast_hsv2rgb.c"
#define MAX_PIXELS 100
#define MAX_BRIGHTNESS 128
#define SPEED 6.0f
#define PERIODS 2.0f
// (100 ledstrip: 100, 255, 0.1, 1)
// (300 ledstrip: 300, 128, 2, 2)
const uint8_t PixelPin = 2;
uint16_t frame = 0;
float phase = 0;
uint32_t old_t = 0;
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(MAX_PIXELS, PixelPin);
void setup() {
}
void loop() {
//float hue_moving = ((float)(frame*SPEED))/360.0f * HSV_HUE_MAX;
uint16_t hue_moving = phase * HSV_HUE_MAX;
float hue_mul = HSV_HUE_MAX/(MAX_PIXELS/PERIODS);
uint8_t *p = strip.Pixels();
for (uint16_t i = 0; i < MAX_PIXELS; i++) {
//float hue_temp = ((float)i)*hue_mul;
//uint16_t hue = ((uint16_t)(hue_temp + hue_moving)) % HSV_HUE_MAX;
uint16_t hue_temp = ((float)i)*hue_mul;
uint16_t hue = (hue_temp + hue_moving) % HSV_HUE_MAX;
fast_hsv2rgb_32bit(hue, 255, MAX_BRIGHTNESS, p++, p++, p++);
//fast_hsv2rgb_8bit(hue, 255, MAX_BRIGHTNESS, p++, p++, p++);
//*p=i; p++; *p=i; p++; *p=i; p++;
}
strip.Dirty();
strip.Show();
frame++;
phase += SPEED/((float)(micros()-old_t));
old_t = micros();
phase = fmod(phase, 1.0f);
}