Shop OBEX P1 Docs P2 Docs Learn Events
P1 Forth question about using Neopixel LEDs — Parallax Forums

P1 Forth question about using Neopixel LEDs

Can someone point me to some explanation and examples of the use of Neopixels with Forth? I've looked at EXTEND.FTH and the included WS2812 support around line 1400, but I need some explanation of LOADMOD and RUNMOD to make sense of it. I've also found RGB and RGBS, but they don't seem to work. I'm obviously missing something. Thanks.

Comments

  • I'd look for these in the tachyon5v7.spin or .list maybe ?
    If anywhere, that would be my first guess .

  • Christof Eb.Christof Eb. Posts: 1,101
    edited 2021-08-06 14:44

    Hi Mike,
    I would not pretend, that I have understood this loadmod stuff. But I have still got Neopixels blinking. :-)

    The most important word is RGBPIN ( instead of LEDPIN !).
    Then you need RGBS
    That's all.

    Edit: There has to be some pause between RGBS commands!

    Good luck, Christof

    1 RGBPIN \ sets the pin 1 to be used and has to be done by the cog, that will use it
    
    \ NeoPixel Ring on Pin 1
    12 3 * bytes ledarray
    
    : clrall
        12 3 * FOR 0 ledarray I + C! NEXT
        ledarray 12 RGBS ;
    
    : setc ( color led -- ) \ 0 grn 1 red 2 blue
        3 * + ledarray + 1 SWAP C! \ set brightness 1 
        ledarray 12 RGBS ;
    
    : clrled ( led -- ) \ 
        3 * ledarray + 
        DUP 0 SWAP C! 
        DUP 1+ 0 SWAP C! 
        2 + 0 SWAP C! 
        ledarray 12 RGBS ;
    
    
    : spinled 
        120 FOR 
            1 I 12 MOD setc 
            100 ms
            clrall
            1 ms
        NEXT ;
    
    
  • ErNaErNa Posts: 1,742
    edited 2021-08-07 20:34

    Hi Mike,
    as I understand there is a little gap in the cog memory where you can load code to. Then you can run this code.

    LOADMOD     ( src dst cnt -- )    C2    Load cog memory from hub memory - used internally by CODE MODULES
    RUNMOD            C    Run the currently loaded code module
    
    

    As RUNMOD has no parameter it just allows you to start the module you loaded before.
    Update: RUNMOD passes parameters as needed to perform the function.

    You find this info in google doc Search for "CODE MODULES" as examples

Sign In or Register to comment.