1#include "DFRobotDFPlayerMini.h"
2#include <SoftwareSerial.h>
3SoftwareSerial mySerial(18, 19);
4DFRobotDFPlayerMini myMP3;
5
6#include <Adafruit_NeoPixel.h>
7#define LED_PIN 8
8
9#define LED_COUNT 24
10Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
11
12
13#include <LiquidCrystal_I2C.h>
14LiquidCrystal_I2C lcd(0x27, 20, 4);
15
16#include <Keypad.h>
17const byte ROWS = 4;
18const byte COLS = 4;
19
20char keys[ROWS][COLS] = {
21 {'1','2','3','A'},
22 {'4','5','6','B'},
23 {'7','8','9','C'},
24 {'*','0','#','D'}
25};
26
27byte colPins[COLS] = {39,41,43,45};
28byte rowPins[ROWS] = {31,33,35,37};
29Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
30
31
32char key,keya;
33int sensore=2,contatore=0,buzzer = 12,selezione = 0, BusyPin = 13,song;
34
35
36String num1,num2,num3,lett;
37int alpha,moltiplica,cifra1,cifra2,cifra3,progress;
38
39void setup() {
40 pinMode (sensore, INPUT);
41 pinMode(BusyPin, INPUT_PULLUP);
42
43 lcd.init();
44 lcd.backlight();
45
46 strip.begin();
47 strip.show();
48 strip.setBrightness(50);
49
50
51 Serial.begin (9600);
52 Serial1.begin(9600);
53 myMP3.begin(Serial1, true);
54
55 delay(1000);
56
57 Serial.println("Setting volume to max");
58 myMP3.volume(30);
59
60
61
62
63
64
65
66 myMP3.EQ(DFPLAYER_EQ_BASS);
67
68
69
70
71 myMP3.enableDAC();
72
73
74
75}
76void loop() {
77 gettone();
78
79
80 lcd.clear();
81 lcd.setCursor(3, 0);
82 lcd.print("J U K E B O X");
83 select();
84
85 myMP3.play(progress);
86 delay(1000);
87durata:
88 if (digitalRead(BusyPin) == LOW) {
89 theaterChase(strip.Color(127, 127, 127), 50);
90 goto durata;
91 }
92 strip.clear();
93 strip.show();
94 }
95
96
97void select() {
98 lcd.setCursor(3, 1);
99 lcd.print("Selezione ");
100
101numero:
102 key = myKeypad.getKey();
103 if (key != NO_KEY && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0'))
104 {
105 num1 = key;
106
107 cifra1 = int(num1.toInt());
108 Serial.println (num1);
109 lcd.setCursor(13, 1);
110 lcd.print(cifra1);
111 tone(buzzer, 770, 300);
112 }
113 else goto numero;
114 delay (200);
115
116numero2:
117 key = myKeypad.getKey();
118 if (key != NO_KEY && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0'))
119 {
120 num2 = key;
121 tone(buzzer, 770, 300);
122
123 cifra2 = int(num2.toInt());
124 lcd.setCursor(14, 1);
125 lcd.print(cifra2);
126 Serial.println (cifra2);
127 }
128 else goto numero2;
129
130numero3:
131 key = myKeypad.getKey();
132 if (key != NO_KEY && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0'))
133 {
134 num3 = key;
135 tone(buzzer, 770, 300);
136 cifra3 = int(num3.toInt());
137 progress = (cifra1*100) + (cifra2*10) + cifra3;
138
139 lcd.setCursor(15, 1);
140 lcd.print(cifra3);
141
142 Serial.println (progress);
143 }
144 else goto numero3;
145
146 lcd.setCursor(1, 3);
147 lcd.print ("Play Song num "); lcd.print(progress);
148
149
150 Serial.print ("selezione ===> "); Serial.print(lett); Serial.println (cifra3);
151 Serial.print ("Progressivo ===> "); Serial.println(progress);
152 delay (200);
153}
154
155void theaterChase(uint32_t color, int wait) {
156 for (int a = 0; a < 10; a++) {
157 for (int b = 0; b < 3; b++) {
158 strip.clear();
159
160 for (int c = b; c < strip.numPixels(); c += 3) {
161 strip.setPixelColor(c, color);
162 }
163 strip.show();
164 delay(wait);
165 }
166 }
167}
168void gettone(){
169
170lcd.clear();
171 lcd.setCursor(3, 0);
172 lcd.print("J U K E B O X");
173 lcd.setCursor(2, 1);
174 lcd.print(" Insert ");
175 lcd.setCursor(0, 2);
176 lcd.print("two x 20 cent coins ");
177 lcd.setCursor(2, 3);
178 lcd.print("for one play");
179
180coin1:
181 if (digitalRead(sensore) == LOW) {
182 contatore ++;
183 Serial.println ("inserita 1");
184 Serial.println (contatore);
185 lcd.setCursor(0, 2);
186 lcd.print(" another coin ");
187 tone(buzzer, 770, 300);
188 tone(buzzer, 970, 400);
189 delay (1000);
190 }
191 else goto coin1;
192 coin2:
193 if(digitalRead(sensore) == LOW) {
194 contatore ++;
195 Serial.println ("inserita 2");
196 Serial.println (contatore);
197 }
198 else goto coin2;
199 tone(buzzer, 770, 300);
200 delay (1000);
201}
annalisa3
2 months ago
Bravo!👏