Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h> // ** BT-Version +++++++++++++++++++++++++++++++++++++
- #include <FastLED.h>
- //---LED SETUP STUFF
- #define LED_COUNT 64
- #define DATA_PIN 6
- #define CLOCK_PIN 8
- //....
- // HardwareSerial-Setup:
- #define btSerial Serial2 // pin 9, 10 for BT-Module
- /*
- //---SOFTWARE SERIAL SETUP STUFF
- // you also could use Serial1 on Teensy
- #define SERIAL_BAUDRATE 57600
- #define SERIAL_TIMEOUT 5
- #define SOFT_RX_PIN 10 // BTCHIP-TX -> NANO-SOFT-RX (2) Yellow with SeedStudio
- #define SOFT_TX_PIN 11 // BTCHIP-RX -> NANO-SOFT-TX (3) White
- // UNO: 2, 3 also works (not all pins support SoftwareSerial
- */
- SoftwareSerial btSerial(SOFT_RX_PIN, SOFT_TX_PIN); // ** BT-Version +++++++++++++++++++++++++++++++++++++
- int btBOOL = 0; //-ACTIVATE BLUETOOTH OR NOT
- byte inbyte; //-SERIAL INPUT BYTE
- int thisarg; //-SERIAL INPUT ARG
- // LED variables ....
- void setup()
- {
- Serial.begin(SERIAL_BAUDRATE); // SETUP HARDWARE SERIAL (USB)
- Serial.setTimeout(SERIAL_TIMEOUT);
- Serial2.begin(SERIAL_BAUDRATE); // SETUP SOFTWARE SERIAL (USB)
- Serial2.setTimeout(SERIAL_TIMEOUT);
- /* //SoftwareSerial
- btSerial.begin(SERIAL_BAUDRATE); // SETUP SOFTWARE SERIAL (USB)
- btSerial.setTimeout(SERIAL_TIMEOUT);
- */
- setupBlueToothConnection();
- LEDS.setBrightness(max_bright);
- FastLED.addLeds<APA102,DATA_PIN,CLOCK_PIN, GBR>(leds, LED_COUNT);
- ....
- }
- //------------------MAIN LOOP------------------
- void loop() {
- if (ledMode != 999) {
- switch (ledMode) {
- case 2: rainbow_fade(); break;
- case 3: rainbow_loop(); break;
- case 4: random_burst(); break;
- case 5: color_bounce(); break;
- case 6: color_bounceFADE(); break;
- case 7: ems_lightsONE(); break;
- case 8: ems_lightsALL(); break;
- // case 9: flicker(); break;
- case 9: bpm(); break;
- case 10: pulse_one_color_all(); break;
- case 11: pulse_one_color_all_rev(); break;
- case 12: fade_vertical(); break;
- case 13: rule30(); break;
- case 14: random_march(); break;
- case 15: rwb_march(); break;
- case 16: radiation(); break;
- case 17: color_loop_vardelay(); break;
- case 18: white_temps(); break;
- case 19: sin_bright_wave(); break;
- // case 20: pop_horizontal(); break;
- case 20: wave_fx(); break;
- case 21: quad_bright_curve(); break;
- case 22: flame(); break;
- case 23: rainbow_vertical(); break;
- // case 24: pacman(); break;
- case 24: juggle(); break;
- case 25: random_color_pop(); break;
- // case 26: ems_lightsSTROBE(); break;
- case 26: sinelon(); break;
- case 27: rgb_propeller(); break;
- case 28: kitt(); break;
- // case 29: matrix(); break;
- // case 29: demo_modeB(); break;
- case 29: demo_modeA(); break;
- case 30: rainbow(); break; // new effects
- case 31: rainbowWithGlitter(); break;
- case 32: confetti(); break;
- case 33: sinelon(); break;
- case 34: juggle(); break;
- case 35: bpm(); break;
- case 50: strip_march_ccw(); break;
- case 51: strip_march_cw(); break;
- case 88: new_rainbow_loop(); break;
- case 888: demo_modeA(); break;
- case 889: demo_modeB(); break;
- }
- }
- //---PROCESS HARDWARE SERIAL COMMANDS AND ARGS
- while (Serial.available() > 0) {inbyte = Serial.read();
- switch(inbyte) {
- case 59: break; //---BREAK IF INBYTE = ';'
- case 108: //---"l" - SET SINGLE LED VALUE
- thisindex = Serial.parseInt();
- thisRED = Serial.parseInt();
- thisGRN = Serial.parseInt();
- thisBLU = Serial.parseInt();
- if (ledMode != 999) {
- ledMode = 999;
- one_color_all(0,0,0);}
- leds[thisindex].setRGB( thisRED, thisGRN, thisBLU);
- show_at_max_brightness_for_power();
- break;
- case 118: //---"v" - SET SINGLE LED VALUE HSV
- thisindex = Serial.parseInt();
- thishue = Serial.parseInt();
- thissat = Serial.parseInt();
- //thisVAL = Serial.parseInt();
- if (ledMode != 999) {
- ledMode = 999;
- one_color_all(0,0,0);}
- leds[thisindex] = CHSV(thishue, thissat, 255);
- break;
- case 100: //---"d" - SET DELAY VAR
- thisarg = Serial.parseInt();
- thisdelay = thisarg;
- break;
- case 115: //---"s" - SET STEP VAR
- thisarg = Serial.parseInt();
- thisstep = thisarg;
- break;
- case 104: //---"h" - SET HUE VAR
- thisarg = Serial.parseInt();
- thishue = thisarg;
- break;
- case 116: //---"t" - SET SATURATION VAR
- thisarg = Serial.parseInt();
- thissat = thisarg;
- break;
- case 98: //---"b" - SET MAX BRIGHTNESS
- max_bright = Serial.parseInt();
- LEDS.setBrightness(max_bright);
- break;
- case 109: //---"m" - SET MODE
- thisarg = Serial.parseInt();
- change_mode(thisarg);
- break;
- case 97: //---"a" - SET ALL TO ONE COLOR BY HSV 0-255
- thisarg = Serial.parseInt();
- one_color_allHSV(thisarg);
- break;
- case 122: //---"z" - COMMAND TO 'SHOW' LEDS
- show_at_max_brightness_for_power();
- break;
- case 81: //---"Q" - COMMAND RETURN VERSION NUMBER
- Serial.print(VERSION_NUMBER);
- break;
- }
- }
- // } // end here w/o BT
- //---PROCESS SOFTWARE SERIAL COMMANDS AND ARGS // ** BT-Version +++++++++++++++++++++++++++++++++++++
- 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
- show_at_max_brightness_for_power();
- break;
- }
- }
- }
- // ** BT-Version +++++++++++++++++++++++++++++++++++++
- //__________________________________________________________________________________
- // This section was used from my BT_Slave Sketch. It initializes the BT-Device
- 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=IsisWings\r\n"); //set the bluetooth name as "IsisWings"
- 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();
- }
Add Comment
Please, Sign In to add comment