This repository has been archived by the owner on Nov 25, 2021. It is now read-only.
forked from Pedro4064/choppeira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.cpp
76 lines (50 loc) · 1.71 KB
/
button.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
#include "button.h"
button::button(int r_pin, int g_pin, int b_pin){
red_pin = r_pin;
blue_pin = b_pin;
green_pin = g_pin;
// set the pin mode to output
pinMode(red_pin,OUTPUT);
pinMode(blue_pin,OUTPUT);
pinMode(green_pin,OUTPUT);
}
void button::set_color(char color){
color_name = color;
switch (color){
case 'R':
analogWrite(red_pin,255);
analogWrite(blue_pin,0);
analogWrite(green_pin,0);
// wait 500 milliseconds, turn of -> so it will blink until the color changes to green
delay(250);
analogWrite(red_pin,0);
analogWrite(blue_pin,0);
analogWrite(green_pin,0);
break;
case 'G':
analogWrite(green_pin,255);
analogWrite(blue_pin,0);
analogWrite(red_pin,0);
break;
case 'Y':
analogWrite(green_pin,50);
analogWrite(blue_pin,0);
analogWrite(red_pin,255);
break;
}
}
void button::turn_led_off(){
// Turn the LED off
analogWrite(red_pin,0);
analogWrite(blue_pin,0);
analogWrite(green_pin,0);
}
void button::boot_routine(){
// blink 3 times the led with the green color, to let the user know the boot sequence is starting
for (int i = 0; i < 3; i++){
button::set_color('G');
delay(1000);
button::turn_led_off();
delay(1000);
}
}