-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjukebox.ino
141 lines (133 loc) · 3.27 KB
/
jukebox.ino
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
#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// String for track number
String track;
//Empty string to clear other strings
String nil;
// String for current track
String current_track;
boolean stringComplete = false; // whether the string is complete
//Matrix Keypad Setup
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = { 4, 5, 6, 7 };
byte colPins[COLS] = { 8, 9, 10 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//Coin/Credit Setup
int count = 2;
int coinPin = 2;
int pulse = 0;
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(coinPin, INPUT);
lcd.print("HELLO");
lcd.setBacklight(YELLOW);
attachInterrupt(0, addCredits, RISING);
}
uint8_t i=0;
void loop() {
uint8_t buttons = lcd.readButtons();
while (count == 0) {
lcd.setCursor(0,0);
lcd.setBacklight(TEAL);
String credits = String(count);
lcd.print("CREDITS: " + credits);
lcd.setCursor(0,1);
lcd.print("INSERT COIN ");
Serial.println("done");
delay(2500);
lcd.clear();
lcd.setBacklight(VIOLET);
lcd.setCursor(0,0);
lcd.print("NOW PLAYING:");
lcd.setCursor(0,1);
nowPlaying();
lcd.print(current_track);
delay(2500);
lcd.clear();
}
while (count > 0) {
String credits = String(count);
lcd.setBacklight(GREEN);
lcd.setCursor(0,0);
lcd.print("CREDITS: " + credits + " ");
lcd.setCursor(0,1);
lcd.print("SELECTION: " + track);
if (track.length() < 4) {
String key = String(keypad.getKey());
if (key != NO_KEY) {
track += key;
lcd.setCursor(0,1);
lcd.print("SELECTION: " + track);
}
}
while (track.length() == 4) {
Serial.println(track);
delay(1000);
char track_found = (char)Serial.read();
if (track_found==('n')) {
lcd.clear();
lcd.setBacklight(RED);
lcd.print("TRACK NOT FOUND!");
lcd.setCursor(0,1);
lcd.print("Try Again");
delay(1000);
track = nil;
lcd.clear();
break;
}
else if (track_found==('y')) {
count--;
String credits = String(count);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("CREDITS: " + credits + " ");
lcd.setCursor(0,1);
lcd.print("Thank You ");
delay(1000);
track = nil;
break;
}
}
}
}
void addCredits() {
pulse++;
while (pulse == 5) {
count = count++;
pulse = 0;
}
}
void nowPlaying() {
current_track = nil;
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
current_track += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}