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
}
}
}
}