Shop OBEX P1 Docs P2 Docs Learn Events
WS2812 RGB and/or SK6812 RGBW flame effects? — Parallax Forums

WS2812 RGB and/or SK6812 RGBW flame effects?

Has anyone written any code to simulate flickering flame light using RGB or RGBW LEDs? I don't need the effect to look like a flame when viewed directly, just produce light that looks like a fire when reflected off of a wall.

Comments

  • I have some RGBW on the way to test out JM's new driver.

    I thinking about connecting a CdS cell to an ADC and recording a real flame. Add some randomize to that pattern and see how it looks.
  • David BetzDavid Betz Posts: 14,516
    edited 2016-10-18 15:37
    I found this: http://www.walltech.cc/neopixel-fire-effect/

    Looks like a pretty good flame effect. I made an attempt to convert his code to Spin and got this:
    var
        long seed
    
    con
        r = 255
        g = r - 40
        b = 40
        
    pub flame(buf, len) | flicker, r1, g1, b1, x
        repeat x from 0 to len - 1
            flicker := ?seed // 150
            r1 := r - flicker
            g1 := g - flicker
            b1 := b - flicker
            if r1 < 0
                r1 := 0
            if g1 < 0
                g1 := 0
            if b1 < 0
                b1 := 0
            long[buf][x] := (r1 << 24) | (g1 << 16) | (b1 << 8)
        time.pause(50 + (||?seed // 100))
    
    It seems to work although the color temperature isn't quite right.
  • Nice, I will revisit when the hardware comes in.
  • David BetzDavid Betz Posts: 14,516
    edited 2016-10-18 17:06
    Here is an update to the flicker code that seems to work a bit better. It is based on the code here: https://github.com/danesparza/Halloweenfire
    var
        long seed
    
    con
        r = 226
        g = 121
        b = 35
        
    pub flame(buf, len) | flicker, r1, g1, b1, x
    
        repeat x from 0 to len - 1
            flicker := ||(?seed // 55)
            r1 := r - flicker
            g1 := g - flicker
            b1 := b - flicker
            if r1 < 0
                r1 := 0
            if g1 < 0
                g1 := 0
            if b1 < 0
                b1 := 0
            long[buf][x] := (r1 << 24) | (g1 << 16) | (b1 << 8)
            
        time.pause(10 + ||(?seed // 103))
    

    Edit: I should mention that I've been using JonnyMac's jm_rgbx_pixel.spin driver.
Sign In or Register to comment.