-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLEDController.cpp
More file actions
38 lines (33 loc) · 867 Bytes
/
Copy pathLEDController.cpp
File metadata and controls
38 lines (33 loc) · 867 Bytes
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
#include "LEDController.h"
#include <Arduino.h>
#define LED_RED_PIN 25
#define LED_GREEN_PIN 26
#define LED_BLUE_PIN 27
#define LED_ON HIGH
#define LED_OFF LOW
void LEDController::begin() {
pinMode(LED_RED_PIN, OUTPUT);
pinMode(LED_GREEN_PIN, OUTPUT);
pinMode(LED_BLUE_PIN, OUTPUT);
setRed();
}
void LEDController::setGreen() {
if (!lastGreen) {
digitalWrite(LED_GREEN_PIN, LED_ON);
digitalWrite(LED_RED_PIN, LED_OFF);
digitalWrite(LED_BLUE_PIN, LED_OFF);
lastGreen = true;
}
}
void LEDController::setRed() {
if (lastGreen) {
digitalWrite(LED_GREEN_PIN, LED_OFF);
digitalWrite(LED_RED_PIN, LED_ON);
digitalWrite(LED_BLUE_PIN, LED_OFF);
lastGreen = false;
}
}
void LEDController::update(int bpm) {
if (bpm >= 60 && bpm <= 80) setGreen();
else setRed();
}