Last active
September 2, 2017 23:46
-
-
Save minakhan01/fb939261db9a21f4d17cfd4723313c0b to your computer and use it in GitHub Desktop.
This file contains 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
//"RBL_nRF8001.h/spi.h/boards.h" is needed in every new project | |
#include <SPI.h> | |
#include <EEPROM.h> | |
#include <boards.h> | |
#include <RBL_nRF8001.h> | |
bool isSalution = false; | |
bool isRhymeSkill = false; | |
bool isOtherChat = false; | |
int salutionNumber = -1; | |
bool isRhymeIntro = false; | |
bool isRhymeOutro = false; | |
bool isRhymeEditorial = false; | |
bool isFurtherInstruction = false; | |
bool isOutroRapAgain = false; | |
void setup() | |
{ | |
// Default pins set to 9 and 8 for REQN and RDYN | |
// Set your REQN and RDYN here before ble_begin() if you need | |
//ble_set_pins(3, 2); | |
// Set your BLE Shield name here, max. length 10 | |
//ble_set_name("My Name"); | |
// Init. and start BLE library. | |
ble_begin(); | |
// Enable serial debug | |
Serial.begin(57600); | |
} | |
unsigned char buf[16] = {0}; | |
unsigned char len = 0; | |
void loop() | |
{ | |
if ( ble_available() ) | |
{ | |
String received = ""; | |
byte data0 = ble_read(); | |
byte data1 = ble_read(); | |
byte data2 = ble_read(); | |
if (data0 == 0x00) { | |
// is salution | |
isSalution = true; | |
isRhymeSkill = false; | |
isOtherChat = false; | |
Serial.println("isSalution"); | |
} | |
else if (data0 == 0x01) { | |
// rhyme skill | |
isSalution = false; | |
isRhymeSkill = true; | |
isOtherChat = false; | |
Serial.println("isRhymeSkill"); | |
} | |
else if (data0 == 0x02) { | |
// other chat | |
isSalution = false; | |
isRhymeSkill = false; | |
isOtherChat = true; | |
Serial.println("isOtherChat"); | |
} | |
if (isSalution) { | |
if (data1 == 0x00) { | |
salutionNumber = 0; | |
Serial.println("salutionNumber = 0"); | |
} | |
else if (data1 == 0x01) { | |
salutionNumber = 1; | |
Serial.println("salutionNumber = 1"); | |
} | |
else if (data1 == 0x02) { | |
salutionNumber = 2; | |
Serial.println("salutionNumber = 2"); | |
} | |
else if (data1 == 0x03) { | |
salutionNumber = 3; | |
Serial.println("salutionNumber = 3"); | |
} | |
else if (data1 == 0x04) { | |
salutionNumber = 4; | |
Serial.println("salutionNumber = 4"); | |
} | |
} | |
if (isRhymeSkill) { | |
if (data1 == 0x00) { | |
// rhyme intro | |
Serial.println("isRhymeIntro"); | |
bool isRhymeIntro = true; | |
bool isRhymeOutro = false; | |
bool isRhymeEditorial = false; | |
bool isFurtherInstruction = false; | |
bool isOutroRapAgain = false; | |
} | |
else if (data1 == 0x01) { | |
// rhyme outro | |
Serial.println("isRhymeOutro"); | |
bool isRhymeIntro = false; | |
bool isRhymeOutro = true; | |
bool isRhymeEditorial = false; | |
bool isFurtherInstruction = false; | |
bool isOutroRapAgain = false; | |
} | |
else if (data1 == 0x02) { | |
// rhyme editorial | |
Serial.println("isRhymeEditorial"); | |
bool isRhymeIntro = false; | |
bool isRhymeOutro = false; | |
bool isRhymeEditorial = true; | |
bool isFurtherInstruction = false; | |
bool isOutroRapAgain = false; | |
} | |
else if (data1 == 0x03) { | |
// further instruction | |
Serial.println("isFurtherInstruction"); | |
bool isRhymeIntro = false; | |
bool isRhymeOutro = false; | |
bool isRhymeEditorial = false; | |
bool isFurtherInstruction = true; | |
bool isOutroRapAgain = false; | |
} | |
else if (data1 == 0x04) { | |
//rap again | |
Serial.println("isOutroRapAgain"); | |
bool isRhymeIntro = false; | |
bool isRhymeOutro = false; | |
bool isRhymeEditorial = false; | |
bool isFurtherInstruction = false; | |
bool isOutroRapAgain = true; | |
} | |
} | |
if (data2 == 0x00) { | |
voiceStart(); | |
} | |
else if (data2 == 0x01) { | |
voiceEnd(); | |
} | |
} | |
ble_do_events(); | |
} | |
void voiceStart() { | |
Serial.println("voice start"); | |
} | |
void printLogs() { | |
Serial.print("isSalution: "+ isSalution); | |
Serial.print("isRhymeSkill: "+ isRhymeSkill); | |
Serial.print("isOtherChat: " +isOtherChat); | |
Serial.print("salutionNumber: "+salutionNumber); | |
Serial.print("isRhymeIntro: "+isRhymeIntro); | |
Serial.print("isRhymeOutro: "+ isRhymeOutro); | |
Serial.print("isRhymeEditorial :"+isRhymeEditorial); | |
Serial.print("isFurtherInstruction: "+isFurtherInstruction); | |
Serial.print("isOutroRapAgain "+isOutroRapAgain); | |
} | |
void voiceEnd() { | |
Serial.println("voice end"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Xin, add your code to voiceStart and voiceEnd <3