-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQRGBLED.cpp
More file actions
89 lines (74 loc) · 1.55 KB
/
SQRGBLED.cpp
File metadata and controls
89 lines (74 loc) · 1.55 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// SQRGBLED.cpp
//
//
// Created by Bradley Clayton on 7/30/12.
// Copyright (c) 2012 Squarepolka. All rights reserved.
//
#include "SQRGBLED.h"
SQRGBLED::SQRGBLED()
{
}
void SQRGBLED::setup(int redPin, int greenPin, int bluePin)
{
_redLED.setup(redPin);
_greenLED.setup(greenPin);
_blueLED.setup(bluePin);
}
void SQRGBLED::colour(int red, int green, int blue, long duration)
{
_redLED.fadeToBrightness(red, duration);
_greenLED.fadeToBrightness(green, duration);
_blueLED.fadeToBrightness(blue, duration);
// Immediately set the colour if the duration is 0
if (duration <= 0)
{
this->loop();
}
}
boolean SQRGBLED::isFading()
{
return _redLED.isFading || _greenLED.isFading || _blueLED.isFading;
}
boolean SQRGBLED::isPulsing()
{
return _redLED.isPulsing || _greenLED.isPulsing || _blueLED.isPulsing;
}
float SQRGBLED::currentRedVal()
{
return _redLED.currentVal();
}
float SQRGBLED::currentGreenVal()
{
return _greenLED.currentVal();
}
float SQRGBLED::currentBlueVal()
{
return _blueLED.currentVal();
}
float SQRGBLED::currentAverageVal()
{
return _redLED.currentVal() + _greenLED.currentVal() + _blueLED.currentVal() / 3;
}
#pragma mark - SQSchedularDelegate Methods
unsigned int SQRGBLED::executionInterval()
{
return 0;
}
// Clock events
void SQRGBLED::loop()
{
// Forward loop event
if (_redLED.isFading)
{
_redLED.loop();
}
if (_greenLED.isFading)
{
_greenLED.loop();
}
if (_blueLED.isFading)
{
_blueLED.loop();
}
}