int val;
int button = 2;
bool sw = true;
int cnt1 = 1;
int cnt2 = 1;
int cnt3 = 1;
int cnt4 = 1;
byte da_pin = 3;
//Note: use the GET diget in order to choose the specific number in the code. Look at the GET digit homework for more info.
void setup() {
Serial.begin(9600);
pinMode(button, INPUT_PULLUP);
}
void loop() {
val = analogRead(A0);
if (digitalRead(button) == LOW) {
folder_play(50, cnt1);
delay(1000);
folder_play(50, cnt2);
delay(1000);
folder_play(50, cnt3);
delay(1000);
folder_play(50, cnt4);
delay(1000);
}
while (sw == true) {
analogRead(A0);
Serial.println(A0);
//Here, I don't know how to connect the cnt's to the A0 (petentiomiter)
delay(300);
if (analogRead(A0)) {
cnt1++;
if (cnt1 > 10) {
cnt1 = 1;
}
cnt2++;
if (cnt2 > 10) {
cnt2 = 1;
}
cnt3++;
if (cnt3 > 10) {
cnt3 = 1;
}
cnt4++;
if (cnt4 > 10) {
cnt4 = 1;
}
}
if (digitalRead(button) == LOW) {
break;
}
}
}
void send_1() {
digitalWrite(da_pin, HIGH);
delayMicroseconds(100);
}
void send_0() {
digitalWrite(da_pin, LOW);
delayMicroseconds(100);
}
void send_da(uint8_t data) {
digitalWrite(da_pin, LOW);
delayMicroseconds(100);
//Start mark
for (byte i = 0; i < 8; i++) { //sending 8 digits
if (bitRead(data, i) == 0) {
send_0();
}
else {
send_1();
}
}
digitalWrite(da_pin, HIGH);
delayMicroseconds(100);
//End mark
}
void folder_play(byte a, byte b) {
byte mp3[8] = {126, 255, 6, 15, (byte)0, a, b, 239};
for (byte i = 0; i < 8; i++) {
send_da(mp3[i]);
}
delay(1);
}