-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget_practice.cpp
More file actions
155 lines (136 loc) · 3.78 KB
/
target_practice.cpp
File metadata and controls
155 lines (136 loc) · 3.78 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int hit_button = 7;
int miss_button = 8;
int hit_count = 0;
int miss_count = 0;
int total_shots = 0;
int Green = 6;
int Red = 9;
int White = 10;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(7, INPUT);
pinMode(8, INPUT);
lcd.setCursor(4, 0);
lcd.print("Welcome To");
lcd.setCursor(2, 1);
lcd.print("Target Practice");
delay(4000);
lcd.setCursor(1,0);
lcd.print(String("Hits: ") + String(hit_count) + String(" "));
lcd.setCursor(1,1);
lcd.print(String("Total Shots: ") + String(total_shots) + String(" "));
// controls leds
Serial.begin(9600);
pinMode(Green, OUTPUT);
digitalWrite(Green, LOW);
pinMode(Red, OUTPUT);
digitalWrite(Red, LOW);
pinMode(White, OUTPUT);
digitalWrite(White, LOW);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// To be used in future iterations for timed target practice
// print the number of seconds since reset:
// lcd.print(millis() / 1000);
// if (count == 0){
// lcd.print(String("Target Practice"));
// }
//
if (digitalRead(hit_button) == LOW && digitalRead(miss_button) == LOW){
digitalWrite(White, HIGH);
} else {
digitalWrite(White, LOW);
}
if (digitalRead(hit_button) == HIGH){
hit_count++;
total_shots = hit_count + miss_count;
lcd.setCursor(1,0);
lcd.print(String("Hits: ") + String(hit_count) + String(" "));
lcd.setCursor(1,1);
lcd.print(String("Total Shots: ") + String(total_shots) + String(" "));
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(500);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(500);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(100);
digitalWrite(Green, LOW);
delay(100);
digitalWrite(Green, HIGH);
delay(1000);
digitalWrite(Green, LOW);
while(digitalRead(hit_button)== HIGH);
}
if (digitalRead(miss_button) == HIGH){
lcd.setCursor(0,0);
miss_count++;
total_shots = hit_count + miss_count;
lcd.setCursor(1,0);
lcd.print(String("Hits: ") + String(hit_count) + String(" "));
lcd.setCursor(1,1);
lcd.print(String("Total Shots: ") + String(total_shots) + String(" "));
digitalWrite(Red, HIGH);
delay(1000);
digitalWrite(Red, LOW);
delay(100);
digitalWrite(Red, HIGH);
delay(1000);
digitalWrite(Red, LOW);
delay(100);
digitalWrite(Red, HIGH);
delay(1000);
digitalWrite(Red, LOW);
delay(100);
digitalWrite(Red, HIGH);
delay(100);
digitalWrite(Red, LOW);
delay(100);
digitalWrite(Red, HIGH);
delay(1000);
digitalWrite(Red, LOW);
while(digitalRead(miss_button)== HIGH);
}
}