Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
Y

yugoos

@yugoos
About
Posts
9
Topics
1
Shares
0
Groups
0
Followers
1
Following
0

Posts

Recent Best Controversial

  • RGB Light, cancel loop?
    Y yugoos

    I made a ws2812 (neopixel) sketch not to long ago, maybe you can use some or all of the code.
    my loop only contains gw.process() for incomming messages (color, brightness, off).
    I made no loops for color shows because i'm not interested in that but is should not be to difficult to adapt the code, there is however a short colorwhipe (chaser) when changing the strip color

    #include <MySensor.h>
    #include <SPI.h>
    
    #include "Adafruit_NeoPixel.h"
    
    #define NUMPIXELS 4   // Number of connected pixels on a single datapin
    #define PIN 4         // Digital output pin
    
    #define NODE_ID AUTO  //254 for testing purpose
    #define CHILD_ID 0  
    
    
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
    long RGB_values[3] = {0,0,0};
    
    MySensor gw;
    
    void setup()
    {
        gw.begin(incomingMessage, NODE_ID, false);
        gw.sendSketchInfo("RGB Node", "1.0");
        gw.present(CHILD_ID, S_RGB_LIGHT);
        strip.begin();
        strip.show(); // Update the strip, to start they are all 'off'
    }
    
    
    void loop()
    {
        gw.process();
    }
    
    void incomingMessage(const MyMessage &message) {
        if (message.type==V_RGB) {
      // starting to process the hex code
            String hexstring = message.getString(); //here goes the hex color code coming from through MySensors (like FF9A00)
            long number = (long) strtol( &hexstring[0], NULL, 16);
            RGB_values[0] = number >> 16;
            RGB_values[1] = number >> 8 & 0xFF;
            RGB_values[2] = number & 0xFF;
    
            colorWipe(Color(RGB_values[0],RGB_values[1],RGB_values[2]), 60);
         }
         
        if (message.type==V_DIMMER) {
          strip.setBrightness(round((2.55*message.getInt())));
          strip.show();
          }
          
        if (message.type==V_LIGHT) {
           if (message.getInt() == 0) {
            strip.clear();
            strip.show();
           }
        }
      
    }
     
    void colorWipe(uint32_t c, uint8_t wait) {
      int i;
     
      for (i=0; i < strip.numPixels(); i++) {
          strip.setPixelColor(i, c);
          strip.show();
          delay(wait);
      }
    }
    
        /* Helper functions */
    
    // Create a 15 bit color value from R,G,B
    uint32_t Color(byte r, byte g, byte b)
    {
      uint32_t c;
      c = r;
      c <<= 8;
      c |= g;
      c <<= 8;
      c |= b;
      return c;
    }
       
    

    It's not the cleanest code but it works for me...

    have fun.

    Troubleshooting
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular