Repository navigation
Expand file tree
/
Copy path2.5Final
More file actions
128 lines (114 loc) · 2.88 KB
/
Copy path2.5Final
File metadata and controls
128 lines (114 loc) · 2.88 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
*/ Light show!
This code goes through 3 different lighting effects and toggles through them as the button is pressed
/*
int boardLED = 13;
int blueLed = 10;
int redLed = 11;
int greenLed = 12;
int button = 8;
boolean last_state = LOW; //button states
boolean current_state = LOW; //button states
boolean led_state = LOW; //boardLED
boolean green_state = LOW;
boolean red_state = LOW;
boolean blue_state = LOW;
int lightDisplayCount = 0;
void setup() //set BoardLED to output
{
pinMode(boardLED, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(button, INPUT);
}
boolean debounce (boolean button_state)
{
boolean current = digitalRead(button);
if (button_state != current) // switch changed states
{
delay(5); // 5 miliseconds delay
current = digitalRead(button); //debounced value
}
return current;
}
void light(int lightDisplay)
{
if (lightDisplay == 1)
{
digitalWrite(redLed, HIGH);
digitalWrite(blueLed, HIGH);
digitalWrite(greenLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, LOW);
digitalWrite(greenLed, LOW);
delay(500);
digitalWrite(redLed, HIGH);
digitalWrite(blueLed, HIGH);
digitalWrite(greenLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, LOW);
digitalWrite(greenLed, LOW);
}
else if (lightDisplay == 3)
{
digitalWrite(redLed,LOW);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, HIGH);
delay(500);
digitalWrite(blueLed, LOW);
digitalWrite(redLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
delay(500);
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, HIGH);
delay(500);
digitalWrite(blueLed, LOW);
}
else if(lightDisplay == 2)
{
digitalWrite(redLed, LOW);
digitalWrite(blueLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, HIGH);
digitalWrite(greenLed, HIGH);
delay(500);
digitalWrite(redLed, HIGH);
digitalWrite(blueLed, LOW);
digitalWrite(greenLed, LOW);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, HIGH);
digitalWrite(greenLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
digitalWrite(blueLed, LOW);
digitalWrite(greenLed, LOW);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(blueLed, LOW);
digitalWrite(greenLed, LOW);
}
}
void loop()
{
current_state = debounce(last_state);
if(last_state == LOW && current_state == HIGH) //buttons been pressed
{
lightDisplayCount++;
light(lightDisplayCount);
if(lightDisplayCount == 3) lightDisplayCount = 0;
}
last_state = current_state; //imporant to always set this
}