-
Notifications
You must be signed in to change notification settings - Fork 2
/
analogLedStrip.cpp
46 lines (41 loc) · 1.1 KB
/
analogLedStrip.cpp
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
#include "analogLedStrip.h"
static unsigned long ccurrent = 0;
static unsigned long cprevious = 0;
static int cinterval = 10;
static uint8_t *colors = NULL;
void setupAnalogStrip()
{
// set pwm range to 0 - 255
analogWriteRange(0xff);
// initialize pins right.
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
digitalWrite(REDPIN, 0);
digitalWrite(GREENPIN, 0);
digitalWrite(BLUEPIN, 0);
writeRgb(0, 0, 0);
yield();
colors = colorinc();
}
void writeRgb(int rval, int gval, int bval)
{
analogWrite(REDPIN, rval);
analogWrite(GREENPIN, gval);
analogWrite(BLUEPIN, bval);
}
void fadeRgb(int speed, int brightness)
{
ccurrent = millis();
if((ccurrent - cprevious) >= cinterval)
{
cprevious = ccurrent;
colors = colorinc();
}
cinterval = stripcontrol.varZero+1;
float brightnessFactor = (float)(((float)stripcontrol.brightness)/100);
int r = colors[RED] * brightnessFactor;
int g = colors[GREEN] * brightnessFactor;
int b = colors[BLUE] * brightnessFactor;
writeRgb(r, g, b);
}