Bluetooth integration help please

Hello :smiley:

It’s my first post so please be gentle :wink:

I’ve just started with Arduino and my ideas are leaping ahead of my abilities so was wondering if I could ask for a little help?

I want to be able to switch through lighting effects on some neopixels that I have, I’ve made an android app to send a number via blueooth (numbers 1-6) to control the patterns on the neopixels.

I want to take the patterns available in the button cycler neopixel example (as below), remove the button and switch between the patterns (scanner, firefly, etc etc) cases? via blueooth.

I’ve done a lot! of reading but am nowhere near capable enough yet to get it to work.

This is the code.

#include <[color=#CC6600]Adafruit_NeoPixel[/color].h>

#define BUTTON_PIN   2    [color=#7E7E7E]// Digital IO pin connected to the button.  This will be[/color]
                          [color=#7E7E7E]// driven with a pull-up resistor so the switch should[/color]
                          [color=#7E7E7E]// pull the pin to ground momentarily.  On a high -> low[/color]
                          [color=#7E7E7E]// transition the button press logic will execute.[/color]

#define PIXEL_PIN    6    [color=#7E7E7E]// Digital IO pin connected to the NeoPixels.[/color]

#define PIXEL_COUNT 16

[color=#7E7E7E]// Parameter 1 = number of pixels in strip,  neopixel stick has 8[/color]
[color=#7E7E7E]// Parameter 2 = pin number (most are valid)[/color]
[color=#7E7E7E]// Parameter 3 = pixel type flags, add together as needed:[/color]
[color=#7E7E7E]//   NEO_RGB     Pixels are wired for RGB bitstream[/color]
[color=#7E7E7E]//   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick[/color]
[color=#7E7E7E]//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)[/color]
[color=#7E7E7E]//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick[/color]
[color=#CC6600]Adafruit_NeoPixel[/color] strip = [color=#CC6600]Adafruit_NeoPixel[/color](PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldState = [color=#006699]HIGH[/color];
[color=#CC6600]int[/color] showType = 0;

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {
  [color=#CC6600]pinMode[/color](BUTTON_PIN, [color=#006699]INPUT_PULLUP[/color]);
  strip.[color=#CC6600]begin[/color]();
  strip.[color=#CC6600]show[/color](); [color=#7E7E7E]// Initialize all pixels to 'off'[/color]
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {
  [color=#7E7E7E]// Get current button state.[/color]
  bool newState = [color=#CC6600]digitalRead[/color](BUTTON_PIN);
  
  [color=#7E7E7E]// Check if state changed from high to low (button press).[/color]
  [color=#CC6600]if[/color] (newState == [color=#006699]LOW[/color] && oldState == [color=#006699]HIGH[/color]) {
    [color=#7E7E7E]// Short delay to debounce button.[/color]
    [color=#CC6600]delay[/color](20);
    [color=#7E7E7E]// Check if button is still low after debounce.[/color]
    newState = [color=#CC6600]digitalRead[/color](BUTTON_PIN);
    [color=#CC6600]if[/color] (newState == [color=#006699]LOW[/color]) {
      showType++;
      [color=#CC6600]if[/color] (showType > 9)
        showType=0;
      startShow(showType);
    }
  }

  [color=#7E7E7E]// Set the last button state to the old state.[/color]
  oldState = newState;
}

[color=#CC6600]void[/color] startShow([color=#CC6600]int[/color] i) {
  [color=#CC6600]switch[/color](i){
    [color=#CC6600]case[/color] 0: colorWipe(strip.Color(0, 0, 0), 50);    [color=#7E7E7E]// Black/off[/color]
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 1: colorWipe(strip.Color(255, 0, 0), 50);  [color=#7E7E7E]// Red[/color]
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 2: colorWipe(strip.Color(0, 255, 0), 50);  [color=#7E7E7E]// Green[/color]
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 3: colorWipe(strip.Color(0, 0, 255), 50);  [color=#7E7E7E]// Blue[/color]
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 4: theaterChase(strip.Color(127, 127, 127), 50); [color=#7E7E7E]// White[/color]
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 5: theaterChase(strip.Color(127,   0,   0), 50); [color=#7E7E7E]// Red[/color]
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 6: theaterChase(strip.Color(  0,   0, 127), 50); [color=#7E7E7E]// Blue[/color]
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 7: rainbow(20);
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 8: rainbowCycle(20);
            [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 9: theaterChaseRainbow(50);
            [color=#CC6600]break[/color];
  }
}

[color=#7E7E7E]// Fill the dots one after the other with a color[/color]
[color=#CC6600]void[/color] colorWipe(uint32_t c, uint8_t wait) {
  [color=#CC6600]for[/color](uint16_t i=0; i<strip.numPixels(); i++) {
      strip.[color=#CC6600]setPixelColor[/color](i, c);
      strip.[color=#CC6600]show[/color]();
      [color=#CC6600]delay[/color](wait);
  }
}

[color=#CC6600]void[/color] rainbow(uint8_t wait) {
  uint16_t i, j;

  [color=#CC6600]for[/color](j=0; j<256; j++) {
    [color=#CC6600]for[/color](i=0; i<strip.numPixels(); i++) {
      strip.[color=#CC6600]setPixelColor[/color](i, Wheel((i+j) & 255));
    }
    strip.[color=#CC6600]show[/color]();
    [color=#CC6600]delay[/color](wait);
  }
}

[color=#7E7E7E]// Slightly different, this makes the rainbow equally distributed throughout[/color]
[color=#CC6600]void[/color] rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  [color=#CC6600]for[/color](j=0; j<256*5; j++) { [color=#7E7E7E]// 5 cycles of all colors on wheel[/color]
    [color=#CC6600]for[/color](i=0; i< strip.numPixels(); i++) {
      strip.[color=#CC6600]setPixelColor[/color](i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.[color=#CC6600]show[/color]();
    [color=#CC6600]delay[/color](wait);
  }
}

[color=#7E7E7E]//Theatre-style crawling lights.[/color]
[color=#CC6600]void[/color] theaterChase(uint32_t c, uint8_t wait) {
  [color=#CC6600]for[/color] ([color=#CC6600]int[/color] j=0; j<10; j++) {  [color=#7E7E7E]//do 10 cycles of chasing[/color]
    [color=#CC6600]for[/color] ([color=#CC6600]int[/color] q=0; q < 3; q++) {
      [color=#CC6600]for[/color] ([color=#CC6600]int[/color] i=0; i < strip.numPixels(); i=i+3) {
        strip.[color=#CC6600]setPixelColor[/color](i+q, c);    [color=#7E7E7E]//turn every third pixel on[/color]
      }
      strip.[color=#CC6600]show[/color]();
     
      [color=#CC6600]delay[/color](wait);
     
      [color=#CC6600]for[/color] ([color=#CC6600]int[/color] i=0; i < strip.numPixels(); i=i+3) {
        strip.[color=#CC6600]setPixelColor[/color](i+q, 0);        [color=#7E7E7E]//turn every third pixel off[/color]
      }
    }
  }
}

[color=#7E7E7E]//Theatre-style crawling lights with rainbow effect[/color]
[color=#CC6600]void[/color] theaterChaseRainbow(uint8_t wait) {
  [color=#CC6600]for[/color] ([color=#CC6600]int[/color] j=0; j < 256; j++) {     [color=#7E7E7E]// cycle all 256 colors in the wheel[/color]
    [color=#CC6600]for[/color] ([color=#CC6600]int[/color] q=0; q < 3; q++) {
        [color=#CC6600]for[/color] ([color=#CC6600]int[/color] i=0; i < strip.numPixels(); i=i+3) {
          strip.[color=#CC6600]setPixelColor[/color](i+q, Wheel( (i+j) % 255));    [color=#7E7E7E]//turn every third pixel on[/color]
        }
        strip.[color=#CC6600]show[/color]();
       
        [color=#CC6600]delay[/color](wait);
       
        [color=#CC6600]for[/color] ([color=#CC6600]int[/color] i=0; i < strip.numPixels(); i=i+3) {
          strip.[color=#CC6600]setPixelColor[/color](i+q, 0);        [color=#7E7E7E]//turn every third pixel off[/color]
        }
    }
  }
}

[color=#7E7E7E]// Input a value 0 to 255 to get a color value.[/color]
[color=#7E7E7E]// The colours are a transition r - g - b - back to r.[/color]
uint32_t Wheel([color=#CC6600]byte[/color] WheelPos) {
  WheelPos = 255 - WheelPos;
  [color=#CC6600]if[/color](WheelPos < 85) {
   [color=#CC6600]return[/color] strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } [color=#CC6600]else[/color] [color=#CC6600]if[/color](WheelPos < 170) {
    WheelPos -= 85;
   [color=#CC6600]return[/color] strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } [color=#CC6600]else[/color] {
   WheelPos -= 170;
   [color=#CC6600]return[/color] strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

[/quote]

Oh well :(

One hint might to remove the posted code, re copy and just paste it normally Format for forum is pretty unreadable..Nice that you used a code box, Though.

Doc