SK6812 RGBW + IR + Nanopixel = problems !Solved!


hi im new here ! :)

i have problems code.

i have googled common problems when using adafruit_neopixel.h , irremote.h

i want controll 25 pixel sk6812 rgbw led strip ir controller using arduino mini pro.


the problem arduino receiving first signal , heard has interrupts.

i post here in hope , possible solution.

sorry messy code , comments may in swedish in code. (not full code maximum allowed length)


so again question is. there possible solution adafruit_neopixel.h , irremote.h interrupts problem ?


the code works fastled problem fastled dont support rgbw


code: [select]


#include <boarddefs.h>
#include <irremote.h>
#include <irremoteint.h>
#include <ir_lego_pf_bitstreamencoder.h>


// initialize leds
#define num_leds 25
#define data_pin 10
#define led_type neo_grbw


#include <adafruit_neopixel.h>
adafruit_neopixel strip = adafruit_neopixel(num_leds, data_pin, led_type + neo_khz800);
/*
  #include "fastled.h"
  crgb leds[num_strips * num_leds_per_strip];
*/

int recv_pin = 1;        //connect receiver pin
irrecv irrecv(recv_pin);
decode_results results;  //decode

byte brightness = 175; //styrka
int bstep = 8;

int loopmode =  0;

//#define mode_off 0
#define mode_staticcolor 1
#define mode_swype 2
#define mode_rainbow 3


unsigned long lastshow = 0;
double vinkelhast = 1.0;
byte vinkel = 0;
int redcolor = 0;
boolean swypeup = false;
// namn på olika färger (hex värdet är 0xwwrrggbb)
// (strip.color converterar från (r,g,b,w)till hex)
uint32_t magenta = 0xff00ff;
uint32_t greenishwhite = strip.color(0, 64, 0, 64);
uint32_t orange =  0xff7f00;
uint32_t white = 0xff000000;
uint32_t purple = 0xff00ff;
uint32_t yellow = 0xffb600;
uint32_t turkos = 0xffff00;

uint32_t currentcolor = orange;

//random function variables
long randnumber1;
long randnumber2;
long randnumber3;

//brightness state
float brightnessstate = 0;

void setup() {
  // put setup code here, run once:

  //fastled.addleds<ws2811, 10, grb>(leds, num_leds).setcorrection( typicalledstrip );
  //fastled.addleds<ws2811, 11, grb>(leds, num_leds).setcorrection( typicalledstrip );
  //fastled.addleds<tm1812, data_pin>(leds, num_leds);

  strip.begin();
  strip.show(); // initialize pixels 'off'

  /*fastled.addleds<neopixel, 10>(leds, 0, num_leds_per_strip);
    fastled.addleds<neopixel, 11, grb>(leds, 0, num_leds_per_strip);
    fastled.addleds<neopixel, 12>(leds, 0, num_leds_per_strip);
    fastled.addleds<neopixel, 13>(leds, 0, num_leds_per_strip);
  */
  serial.begin(9600);   // debuging
  irrecv.enableirin(); // starting receiver
  off();               // set pixels off
  //rainbowcycle(2);
  //delay(200);
}

void loop() {

  // switch case, ir kontrol    case 0xffxxxx xxxx = ir kod
  if (irrecv.decode(&results)) {
    switch (results.value)  { //när den får en signal från fjärren


      case 0xff3ac5:  // brightness+
        serial.println("b+");
        if (brightness <= (255 - bstep)) //undvik overflow
          brightness += bstep;
        else
          brightness = 255;
        strip.setbrightness(brightness);
        break;


      case 0xffba45:  // brightness-
        serial.println("b-");
        if (brightness >= bstep)
          brightness -= bstep;
        strip.setbrightness(brightness);
        showstrip();
        break;

      case 0xff827d:
        serial.println("play");
        break;


      case 0xff02fd:
        serial.println("off"); //off
        off();
        loopmode = 0;
        break;

      case 0xff1ae5:
        serial.println("red");
        swypeup = true;
        currentcolor = 0xff0000;
        loopmode = mode_staticcolor;
        break;


      case 0xff9a65:
        serial.println("green");
        swypeup = true;
        currentcolor = 0x00ff00;
        loopmode = mode_staticcolor;
        break;

      case 0xffa25d:
        serial.println("blue");
        swypeup = true;
        loopmode = mode_staticcolor;
        currentcolor = 0x0000ff;
        break;


      case 0xff22dd:
        serial.println("white");
        swypeup = true;//swype animation on color change
        loopmode = mode_staticcolor;
        currentcolor = 0xff000000;
        break;



    }
   
    irrecv.resume(); // receive next value
  }

as understand it, neopixel routine has disable interrupts output led data (otherwise strict timing of pulses out leds messed up).

the ir routine needs use interrupt pick input signal.

this should problem if continually outputting leds (which continually disables interrupts), seems waiting ir signal updating leds, returning wait ir signal.

so... think there else wrong.

try commenting out switch( results.value ){ ... } , serial.print( results.value )

i'm not familiar ir library using, may worth checking simple example code uses it.

i'm *guessing* irrecv.decode(&results) might continually returning true after first receive, leds continually being written.

you try setting results.value= 0; before irrecv.resume();

yours,
  tonywilk




Arduino Forum > Using Arduino > Programming Questions > SK6812 RGBW + IR + Nanopixel = problems !Solved!


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???