forked from ghztomash/MIDIElements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLed.cpp
84 lines (70 loc) · 1.38 KB
/
Led.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
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
// MIDI Elements LED class
// Library to simplifly handling of compontents for MIDI controllers
// Created by Tomash Ghz
// www.tomashg.com
#include "Led.h"
//-----------------------------------------------------------------------------------
// constructor
Led::Led(byte p){
Led(p,0,0,false);
}
Led::Led(byte p, byte c, byte n){
Led(p,c,n,false);
}
Led::Led(byte p, byte c, byte n, bool a){
pin=p;
channel=c;
number=n;
pwm=a;
state=false;
pinMode(pin,OUTPUT);
}
// destructor
Led::~Led(){
}
void Led::setOn(byte c, byte n, byte v){
if((channel==c)&&(number==n)){
if(v==0) // velocity 0 turn led off
digitalWrite(pin,LOW);
else // turn led on
{
if(pwm) // analog write
analogWrite(pin,map(v,0,127,0,255));
else
digitalWrite(pin,HIGH);
state=true;
}
}
}
void Led::setOff(byte c, byte n, byte v){
if((channel==c)&&(number==n)){ // note off, turn led off
digitalWrite(pin,LOW);
state=false;
}
}
void Led::setOnSilent(byte c, byte n, byte v){
if((channel==c)&&(number==n)){
if(v==0){ // velocity 0 turn led off
state=false;
}
else // turn led on
{
state=true;
}
}
}
void Led::setOffSilent(byte c, byte n, byte v){
if((channel==c)&&(number==n)){ // note off, turn led off
state=false;
}
}
void Led::set(bool s){
state=s;
}
void Led::set(){
if(state)
digitalWrite(pin,HIGH);
else
digitalWrite(pin,LOW);
}