Neopixel ring 16 - Busy light - 433mhz

hi there, I found this great neopixel code that i changed a bit to work as a busy light for my wife's home-office. code works great, but i have these 433mhz send/reciever that i would like to implement.
I'm not knowing anything from these sender/recievers... anyone who could help me?

433mhz Found that i have to make a transmitter and a receiver code, but don't know how...

#include <Adafruit_NeoPixel.h>

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

#define PIXEL_PIN    9   // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 16   // number of neopixel (change this accordingly)

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


bool oldState = HIGH;
int showType = 0;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

}

void loop() {
  // Get current button state.
  bool newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 3)
        showType=0;
      startShow(showType);
    }
  }

  // Set the last button state to the old state.
  oldState = newState;
}

void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            break;
    case 1: colorWipe(strip.Color(0,255,0), 20);  // Green
            break;
    case 2: colorWipe(strip.Color(255, 110 , 0), 20);  // Yellow
            break;
    case 3: colorWipe(strip.Color(255, 0, 0), 20);
            break;
  }
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    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);
}

Neopixel ring

What do you want to do with them? Communicate between 2 arduinos? Communicate the home-office status somewhere else? At the bare minimum, you will need 2 arduinos.

More details please.

I would like to have the send unit with a pushbutton at the desk and the receiver at the attic door downstairs. So my kids can see green, orange or red light when they would like to ask mom something.

I have 2 nano's wired with the 433mhz and the work fine. Tested with a 'hello world'' message, code found on www.

But I can't rewrite the neopixel-code so it works from a remote unit.
My coding-skills are practically non-existing... I'm a trail&error worker, starting from the good work found on www.

Be aware that NeoPixel code turns interrupts off and they're needed for the common implementation of 433MHz OOK.

By the way, the WWW has reference and educational material available, not just things to copy (I assume that's what you mean by "good works").

do you mean it can't be done?

Reliability will be an issue if you want to display animations. If you just want it to show a single color and then wait for a message, you should be able to get it to work.
Start with setting up the 433Mhz sketches and the UI on the transmitter side (the buttons) . Once you've done that and have successfully received a message on the receiving end, simply set all leds to a single color, and wait for the next message.

If you need animations, you can use dual processors.

code is ready. With help from FB.

SEND:

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include <Adafruit_NeoPixel.h>

#define BUTTON_PIN   2
#define PIXEL_PIN    3   
#define PIXEL_COUNT  16

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

bool oldState = HIGH;
int showType = 0;

RH_ASK driver;

void setup(){
  

    pinMode(BUTTON_PIN, INPUT_PULLUP);
    strip.begin();
    strip.show();
    Serial.begin(9600);    // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{

bool newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 3)
        showType=0;
        startShow(showType);
    }
  }

  // Set the last button state to the old state.
  oldState = newState;

 
    const char *msg;
    switch(showType){
    case 0:
    msg = "Col0";
    break;
    case 1:
    msg = "Col1";
    break;
    case 2:
    msg = "Col2";
    break;
    case 3:
    msg = "Col3";
    break;
    }
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(500);
    Serial.println(msg);
}

void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            break;
    case 1: colorWipe(strip.Color(0,255,0), 20);  // Green
            break;
    case 2: colorWipe(strip.Color(255, 110 , 0), 20);  // Yellow
            break;
    case 3: colorWipe(strip.Color(255, 0, 0), 20);
            break;
  }
}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

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

RECIEVE:

#include <Adafruit_NeoPixel.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

#define PIXEL_PIN    3   
#define PIXEL_COUNT 16

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

RH_ASK driver;

void setup()
{
    strip.begin();
    strip.show();
    Serial.begin(9600);  // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    uint8_t buf[4];
    uint8_t buflen = sizeof(buf);
    if (driver.recv(buf, &buflen)) // Non-blocking
    {
      int i;
      // Message with a good checksum received, dump it.
            Serial.print("Message: ");
      String RecString = (char*)buf;
    //Serial.println(RecString.charAt(3)); 
    switch (RecString.charAt(3)) {
    case '0': colorWipe(strip.Color(0, 0, 0), 20);    // Black/off
            break;
    case '1': colorWipe(strip.Color(0, 255, 0), 20);  // Green
            break;
    case '2': colorWipe(strip.Color(255, 170, 0), 20);  // Yellow
            break;
    case '3': colorWipe(strip.Color(255, 0, 0), 20);
            break;
    }          
    }
}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

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

Since you are a self-proclaimed newbie.... The above indentation of the code would suggest that both of those statements are associated with the if() but they are not since you did not use backets '{' '}'
You should always get in the habit of using them. You can also auto format your code (Ctrl-T) and you will notice that the code changes to

      if (showType > 3)
        showType=0;
      startShow(showType);

which helps humans realize what is going on. There are several instances of this in your code.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.