Help with fixing code

Microsoft's MakeCode platform for easy blocks-style programming

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
DazednConfused
 
Posts: 36
Joined: Fri Dec 09, 2022 2:48 pm

Help with fixing code

Post by DazednConfused »

So I have a LED strip that I need to slowly fade from color to color.
I found this code and entered into MakeCode. It says Line 22: ';" expected. I tried putting it everywhere in the line but it still says there's an error.

Code: Select all

define, TRANSITION_MILLIS, 5000

byte, colSrc[3], colDst[3], colCur[3]; //R=0, G=1, B=2
byte, idx; //used as global indexer
unsigned, long, transitionStart, transitionPos;

void randomColor(byte * col)
{
    for (idx = 0; idx < 3; i++) col[idx] = random(256);
}

void setup()
{
    randomSeed(analogRead(A0));
    randomColor(colSrc);
    randomColor(colDst);
    transitionStart = millis();
}

void loop()
{
    unsigned long; loop;Ms = millis();
    transitionPos = loopMs - transitionStart;
    if (transitionPos >= TRANSITION_MILLIS) {
        //done
        memcpy(colSrc, colDst, sizeof(colDst)); //copy dst to src
        memcpy(colCur, colDst, sizeof(colDst)); //set current color
        randomColor(colDst); //new dst
        transitionStart = loopMs;
    }
    else {
        //in progress
        for (idx = 0; idx < 3; idx++) colCur[idx] = map(transitionPos, 0, TRANSITION_LENGTH - 1, colSrc[idx], colDst[idx]);
    }

    //Here "colCur" is the current RGB value of the transition

}

User avatar
mikeysklar
 
Posts: 13544
Joined: Mon Aug 01, 2016 8:10 pm

Re: Help with fixing code

Post by mikeysklar »

@DazednConfused,

Are you really using MakeCode, because this looks like C.

What hardware are you using? Controller board and LED strip model.

If you were using Makecode I would just use 'set strip brightness <value>' code block in a loop going up and down with a delay to see the fade.

User avatar
DazednConfused
 
Posts: 36
Joined: Fri Dec 09, 2022 2:48 pm

Re: Help with fixing code

Post by DazednConfused »

I put it into make code but I guess it's Javascript?
I have a Gemma M0 and LED strip lights you get from the store

User avatar
mikeysklar
 
Posts: 13544
Joined: Mon Aug 01, 2016 8:10 pm

Re: Help with fixing code

Post by mikeysklar »

I take it the strip lights are not from the Adafruit store? We can help you with the Adafruit neopixels and dotstars, but you will have to make a go of things on your own with other devices.

User avatar
DazednConfused
 
Posts: 36
Joined: Fri Dec 09, 2022 2:48 pm

Re: Help with fixing code

Post by DazednConfused »

No they are not. Thank you!

Post Reply
Please be positive and constructive with your questions and comments.

Return to “MakeCode”