Created
May 19, 2021 14:30
-
-
Save esthicodes/94a748144cdf70c9cf6a0a9c5bdb641d to your computer and use it in GitHub Desktop.
Arduino Project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <SoftwareSerial.h> | |
#include <DFRobotDFPlayerMini.h> | |
SoftwareSerial Vicon_BTSerial(2,3); | |
SoftwareSerial Master_BTSerial(4,9); | |
SoftwareSerial MP3Module(7, 6); | |
DFRobotDFPlayerMini MP3Player; | |
int speakerButton = 12; | |
int buzzer = 8; | |
int vicon_data = 0; | |
int subject_data = 0; | |
int valid_subject = 0; | |
int subject_count = 0; | |
int temp_vicon = 0; | |
bool SUCCESS = false; | |
bool guide_flag = false; | |
void target_sound(); | |
void terminate_sound(); | |
void success_sound(); | |
void fail_sound(); | |
void guide_correct_sound(); | |
void setup() | |
{ | |
Serial.begin(9600); | |
Master_BTSerial.begin(9600); | |
Vicon_BTSerial.begin(9600); | |
MP3Module.begin(9600); | |
pinMode(speakerButton, INPUT_PULLUP); | |
if (!MP3Player.begin(MP3Module)) | |
{ // MP3 모듈을 초기화 | |
Serial.println(F("Hello, whatever:")); | |
while (true); | |
} | |
delay(1); | |
MP3Player.volume(30); // 볼륨을 조절합니다. 0~30까지 설정 | |
Vicon_BTSerial.read(); | |
Master_BTSerial.read(); | |
Vicon_BTSerial.println("end"); | |
} | |
void loop() | |
{ | |
// vicon_data = 0; | |
// subject_data = 0; | |
// | |
// if(digitalRead(speakerButton)==LOW) | |
// { | |
// target_sound(); | |
// 유효한???valid_subject = 0; | |
// Vicon_BTSerial.println("request"); | |
// } | |
// Master_BTSerial.listen(); | |
while(Master_BTSerial.available()!=0) | |
{ | |
subject_data = Master_BTSerial.read(); | |
Serial.println(subject_data); | |
if(subject_data!=0) | |
{ | |
valid_subject = subject_data; // subject_clicked!! | |
Serial.println(valid_subject); | |
Master_BTSerial.end(); | |
break; | |
} | |
} | |
// Vicon_BTSerial.listen(); | |
// while(Vicon_BTSerial.available() && Vicon_BTSerial.readStringUntil('.').toInt() > 0) | |
// { | |
// if(valid_subject!=0) | |
// { | |
// | |
// vicon_data = Vicon_BTSerial.readStringUntil('.').toInt(); | |
// | |
// if(0 < vicon_data && vicon_data < 150) | |
// { | |
// if(!guide_flag) | |
// { | |
// success_sound(); | |
// SUCCESS = true; | |
//// Serial.print("vicon:: "); | |
//// Serial.println(vicon_data); | |
// } | |
// } | |
// else | |
// { | |
// fail_sound(); | |
// SUCCESS = false; | |
// subject_count++; | |
// | |
// while(vicon_data > 150) | |
// { | |
// temp_vicon = Vicon_BTSerial.readStringUntil('.').toInt(); | |
// | |
// if(temp_vicon > 0) | |
// { | |
// vicon_data = temp_vicon; | |
// tone(buzzer, vicon_data*1.5, 100); | |
// } | |
//// Serial.print("vicon:: "); | |
//// Serial.println(vicon_data); | |
// } | |
// guide_correct_sound(); | |
// Vicon_BTSerial.end(); | |
// } | |
// | |
// valid_subject = 0; | |
// | |
// Vicon_BTSerial.println("end"); | |
// vicon_data = 0; | |
// break; | |
// } | |
// } | |
// | |
// if (subject_count==3 || SUCCESS) | |
// { | |
// subject_count = 0; | |
// SUCCESS = false; | |
// terminate_sound(); | |
// } | |
} | |
void target_sound() //target sound starts from 0; | |
{ | |
for(int i=0; i<5; ++i) //why not i++? | |
{ | |
tone(buzzer, 500, 500);//means the buzzer will sound for 5secs | |
delay(1000); // delay for 10 secs. | |
} | |
} | |
void terminate_sound() //why is here terminating the sound? | |
{ | |
tone(buzzer, 2093, 100); delay(100); //different tone, different buzzer | |
tone(buzzer, 2349, 100); delay(100); | |
tone(buzzer, 2637, 100); delay(100); | |
} | |
void guide_correct_sound() | |
{ | |
MP3Player.play(2); | |
delay(1200); | |
} | |
void success_sound() | |
{ | |
MP3Player.play(5); | |
delay(2000); | |
} | |
void fail_sound() | |
{ | |
MP3Player.play(4); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment