Combining "led = ON" code with LED neopixel function.

First off, admittedly I am a script kiddy. I have basic coding knowledge but after exhausting Google searches and my patience, I must ask for help.

My project is simple in concept: an LED “beacon” that can be triggered remotely.

  • I have one code that turns on an LED via RF, (pin HIGH or LOW)

  • I have a neopixel sequence

i would like the code to run the neopixel function in lieu of turning LED pin on or off.

(icing on the cake would be to have two buttons on the RF transmitter that, when respectively engaged, trigger two separate functions… But one step at a time.

The respective codes follow:

// ---------------------------------------------------------------------------------------------------------------------

//code #1 (receiver code to trigger LED when transmitter sends “button code”

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

int ledPin = 6;
unsigned long last = millis();//set timer

void setup() {
mySerial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {

bool ledState = digitalRead(ledPin);//check if the LED is turned on or off. Returns 1 or 0

if(mySerial.available() > 1){
int input = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)

if(millis() - last > 250){//if time now is 250 milliseconds greater than last time
if(ledState == 0 && input == 1234){//if LED is off and button code is ok
digitalWrite(ledPin, HIGH);
}else if(ledState == 1 && input == 1234){//if LED is on and button code is ok
digitalWrite(ledPin, LOW);
}

}

mySerial.flush();//clear the serial buffer for unwanted inputs
last = millis();//reset timer
}
delay(20);//delay little for better serial communication

}

// --------------------------------------------------------------------------------------------------------------------

// code #2 (“candycane” neopixel sequence

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif

#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin();
strip.setBrightness(64);
strip.show(); // Initialize all pixels to ‘off’
}

void loop() {
candyChase(100);
}

void candyChase(uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i+q, 255,255,255); //turn every pixel white
}
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 255,0,0); //turn every third pixel red
}
strip.show();

delay(wait);

for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

Hey script kiddie, Please read the forum rules you're breaking. If you ever want to be more than a script kiddie, it is absolutely crucial that you learn how to read the instructions and documentation FIRST.

How to use this forum - please read

What have you tried so far? This is a place to get help with code that YOU write. If you want someone to just write it for you then pop over to the gigs and collaborations section and hire someone. This isn't a free code writing service for script kiddies.

Per Delta_G’s guidance, here is what i’ve come up with so far, using my limited knowledge and resources.

The syntax is based on a forum guide on combining code, (which I cannot find anymore), where the respective loops are turned into functions and an “if” command between the functions dictates whether the result is triggered or not.

Here follows the code:

// ---------------------------------------------------------------------------------------------------------------------------

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

int ledPin = 6;
unsigned long last = millis();//set timer

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif

#define ledPin 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, ledPin, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin();
strip.setBrightness(64);
strip.show(); // Initialize all pixels to ‘off’
mySerial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop () {
hcrxLoopCode();
if(ledPin == LOW){
return;
}
rainbowLoopCode();
}

void hcrxLoopCode() {
boolean ledState = digitalRead(ledPin);//check if the LED is turned on or off. Returns 1 or 0

if(mySerial.available() > 1){
int input = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)

if(millis() - last > 250){//if time now is 250 milliseconds greater than last time
if(ledState == 0 && input == 1234){//if LED is off and button code is ok
digitalWrite(ledPin, HIGH);
}else if(ledState == 1 && input == 1234){//if LED is on and button code is ok
digitalWrite(ledPin, LOW);
}
}
mySerial.flush();//clear the serial buffer for unwanted inputs
last = millis();//reset timer
}
delay(20);//delay little for better serial communication
}

void rainbowLoopCode() {
rainbowCycle(20);
}

void rainbowCycle(uint8_t wait) {
uint16_t i, j;

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

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

You didn't read the link I gave you did you. Why should anyone help you if you are just going to thumb your nose at the forum guidelines?