1
2#include <Wire.h>
3#include <LiquidCrystal_I2C.h>
4
5LiquidCrystal_I2C myDisplay(0x27,16,2);
6
7#define greenLED 2
8#define yellowLED 3
9#define redLED 4
10#define sensor1 8
11#define sensor2 9
12#define sensor3 10
13#define sensor4 11
14#define sensor5 12
15#define sensor6 13
16
17void setup()
18{
19 myDisplay.init();
20 myDisplay.backlight();
21 myDisplay.print("PLAY!");
22 delay(2000);
23 myDisplay.setCursor(0,0);
24 myDisplay.print(" ");
25 myDisplay.setCursor(6,0);
26 myDisplay.print("GO GO GO");
27 delay(2000);
28 myDisplay.setCursor(0,0);
29 myDisplay.print(" ");
30
31 Serial.begin(9600);
32 pinMode(sensor1, INPUT);
33 pinMode(sensor2, INPUT);
34 pinMode(sensor3, INPUT);
35 pinMode(sensor4, INPUT);
36 pinMode(sensor5, INPUT);
37 pinMode(sensor6, INPUT);
38 pinMode(greenLED, OUTPUT);
39 pinMode(yellowLED, OUTPUT);
40 pinMode(redLED, OUTPUT);
41
42 digitalWrite(greenLED, LOW);
43 digitalWrite(yellowLED, LOW);
44 digitalWrite(redLED, LOW);
45
46}
47
48
49int i=0;
50void loop() {
51 if (digitalRead(sensor1)==HIGH){
52 i=i+20;
53 myDisplay.clear();
54 myDisplay.setCursor(5,0);
55 myDisplay.print("+20!");
56 digitalWrite(greenLED, HIGH);
57 delay(2000);
58 digitalWrite(greenLED, LOW);
59 myDisplay.clear();
60 }
61
62 if (digitalRead(sensor2)==HIGH){
63 i=i+50;
64 myDisplay.clear();
65 myDisplay.setCursor(5,0);
66 myDisplay.print("+50!");
67 digitalWrite(greenLED, HIGH);
68 digitalWrite(yellowLED, HIGH);
69 delay(2000);
70 digitalWrite(greenLED, LOW);
71 digitalWrite(yellowLED, LOW);
72 myDisplay.clear();
73 }
74
75 if (digitalRead(sensor3)==HIGH){
76 i=i+100;
77 myDisplay.clear();
78 myDisplay.setCursor(5,0);
79 myDisplay.print("+100!");
80 digitalWrite(greenLED, HIGH);
81 digitalWrite(yellowLED, HIGH);
82 digitalWrite(redLED, HIGH);
83 delay(2000);
84 digitalWrite(greenLED, LOW);
85 digitalWrite(yellowLED, LOW);
86 digitalWrite(redLED, LOW);
87 myDisplay.clear();
88 }
89
90 if (digitalRead(sensor4)==HIGH){
91 i=i+20;
92 myDisplay.clear();
93 myDisplay.setCursor(5,0);
94 myDisplay.print("+20!");
95 digitalWrite(greenLED, HIGH);
96 delay(2000);
97 digitalWrite(greenLED, LOW);
98 myDisplay.clear();
99 }
100
101 if (digitalRead(sensor5)==HIGH){
102 i=i+50;
103 myDisplay.clear();
104 myDisplay.setCursor(5,0);
105 myDisplay.print("+50!");
106 digitalWrite(greenLED, HIGH);
107 digitalWrite(yellowLED, HIGH);
108 delay(2000);
109 digitalWrite(greenLED, LOW);
110 digitalWrite(yellowLED, LOW);
111 myDisplay.clear();
112 }
113
114 if (digitalRead(sensor6)==HIGH){
115 i=i+100;
116 myDisplay.clear();
117 myDisplay.setCursor(5,0);
118 myDisplay.print("+100!");
119 digitalWrite(greenLED, HIGH);
120 digitalWrite(yellowLED, HIGH);
121 digitalWrite(redLED, HIGH);
122 delay(2000);
123 digitalWrite(greenLED, LOW);
124 digitalWrite(yellowLED, LOW);
125 digitalWrite(redLED, LOW);
126 myDisplay.clear();
127 }
128
129 if (i>=500){
130 myDisplay.clear();
131 myDisplay.setCursor(4,0);
132 myDisplay.print("YOU WIN!");
133 for (int j=0; j<=15; j=j+1){
134 digitalWrite(greenLED, HIGH);
135 digitalWrite(yellowLED, HIGH);
136 digitalWrite(redLED, HIGH);
137 delay(100);
138 digitalWrite(greenLED, LOW);
139 digitalWrite(yellowLED, LOW);
140 digitalWrite(redLED, LOW);
141 delay(100);
142 }
143 i=0;
144 myDisplay.clear();
145 myDisplay.setCursor(0,0);
146 myDisplay.print("New Game");
147 delay(2000);
148 myDisplay.setCursor(0,0);
149 myDisplay.print(" ");
150 myDisplay.setCursor(6,0);
151 myDisplay.print("GO!");
152 delay(2000);
153 myDisplay.setCursor(0,0);
154 myDisplay.print(" ");
155 }
156
157 myDisplay.setCursor(0,0);
158 myDisplay.print("Your Score:");
159 myDisplay.setCursor(0,1);
160 myDisplay.print(i,DEC);
161}
162
163
164
Anonymous user
2 years ago
Nice project! https://inro.in/lucky-patcher/ https://inro.in/9apps/ https://inro.in/vidmate/