Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SoftwareSerial btSerial(SOFT_RX_PIN, SOFT_TX_PIN);
- int btBOOL = 0; //-ACTIVATE BLUETOOTH OR NOT
- byte inbyte; //-SERIAL INPUT BYTE
- int thisarg; //-SERIAL INPUT ARG
- void setup() {
- btSerial.begin(SERIAL_BAUDRATE); // SETUP SOFTWARE SERIAL (USB)
- btSerial.setTimeout(SERIAL_TIMEOUT);
- ...
- void loop() {
- if (ledMode != 999) {
- switch (ledMode) {
- case 1: rainbow_fade(); break;
- case 2: rainbow_loop(); break;
- ...
- }
- }
- //---PROCESS SOFTWARE SERIAL COMMANDS AND ARGS
- while (btSerial.available() > 0) {
- inbyte = btSerial.read();
- if (btSerial.overflow()){Serial.println("SoftwareSerial overflow!");}
- switch(inbyte) {
- case 59: break; //---BREAK IF INBYTE = ';'
- case 108: //---"l" - SET SINGLE LED VALUE
- thisindex = btSerial.parseInt();
- thisRED = btSerial.parseInt();
- thisGRN = btSerial.parseInt();
- thisBLU = btSerial.parseInt();
- if (ledMode != 999) {
- ledMode = 999;
- one_color_all(0,0,0);}
- leds[thisindex].setRGB( thisRED, thisGRN, thisBLU);
- break;
- case 100: //---"d" - SET DELAY VAR
- thisarg = btSerial.parseInt();
- thisdelay = thisarg;
- break;
- case 115: //---"s" - SET STEP VAR
- thisarg = btSerial.parseInt();
- thisstep = thisarg;
- break;
- case 104: //---"h" - SET HUE VAR
- thisarg = btSerial.parseInt();
- thishue = thisarg;
- break;
- case 116: //---"t" - SET SATURATION VAR
- thisarg = btSerial.parseInt();
- thissat = thisarg;
- break;
- case 98: //---"b" - SET MAX BRIGHTNESS
- max_bright = btSerial.parseInt();
- LEDS.setBrightness(max_bright);
- break;
- case 109: //---"m" - SET MODE
- thisarg = btSerial.parseInt();
- change_mode(thisarg);
- break;
- case 99: //---"c" - CLEAR STRIP
- one_color_all(0,0,0);
- break;
- case 97: //---"a" - SET ALL TO ONE COLOR BY HSV 0-255
- thisarg = btSerial.parseInt();
- one_color_allHSV(thisarg);
- break;
- case 122: //---"z" - COMMAND TO 'SHOW' LEDS
- LEDS.show();
- break;
- }
- }
- }
- void setupBlueToothConnection()
- {
- btSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
- btSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
- btSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
- btSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
- btSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
- btSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
- delay(2000); // This delay is required.
- btSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
- Serial.println("The slave bluetooth is inquirable!");
- Serial.println("PIN 0000");
- Serial.println("38400 Baud");
- delay(2000); // This delay is required.
- btSerial.flush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement