Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

CPE and external Neopixel issues changing colors in array
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CPE and external Neopixel issues changing colors in array

by jonahlee on Sun Feb 16, 2020 7:31 pm

So I am a total noob, and any programming experience I have had was a long long time ago. I am building a Spaceship cockpit for a short film, and I want to have some interactive lights on the panel that can be easily changed for different lighting effects. To that end I picked up 3 circuit playground expresses and 3 different external neoixels. I had wanted to use some toggle switches to change lighting effects, but realized it wasn't going to work like I wanted, so I have been attempting using Makecode and an array to be able to change the colors with the A and B buttons on the CPE.

I wrote this code with an array, but I only get the first 3 colors I setup and the A and B buttons don't seem to do anything. I was trying playing with moving different items between the forever and on start blocks, but when I did that I didn't get anything.



Here is the MakeCode and then the Javascript below.

Code: Select all | TOGGLE FULL SIZE
input.buttonA.onEvent(ButtonEvent.Click, function () {
    _1A += 3
    _1B += 3
    _1C += 3
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    _1A += 1
    _1B += 1
    _1A += 1
})
input.buttonsAB.onEvent(ButtonEvent.Click, function () {
    _1A = 0
    _1B = 1
    _1C = 2
})
let _1C = 0
let _1B = 0
let _1A = 0
let list = [Colors.Blue, Colors.Green, Colors.Indigo, Colors.Orange, Colors.Pink, Colors.Yellow, Colors.Red, Colors.Violet, Colors.Orange]
let Main_Strip = light.createStrip(pins.A1, 24)
let Traveler = Main_Strip.range(0, 4)
let Traveler2 = Main_Strip.range(4, 4)
_1A = 0
_1B = 1
_1C = 2
let Color1A = list[_1A]
let Color1B = list[_1B]
let Color1C = list[_1C]
Main_Strip.setAll(Color1A)
Traveler.setAll(Color1B)
Traveler2.setAll(Color1C)
forever(function () {
    Main_Strip.move(LightMove.Rotate, 1)
    pause(50)
})


Does anyone have an examples that could help me with this coding? Any help would be greatly appreciated.

jonahlee
 
Posts: 11
Joined: Sat Feb 01, 2020 6:42 pm

Re: CPE and external Neopixel issues changing colors in arra

by jonahlee on Sun Feb 16, 2020 8:36 pm

Ha, I am so confused. I seem to have figured out how to make the color change with the buttons on the CPE to work, but then the rotation no longer seems to work, though something is going as the travelers are pulsing a bit.



Code: Select all | TOGGLE FULL SIZE
input.buttonA.onEvent(ButtonEvent.Click, function () {
    A += 3
    B += 3
    C += 3
    if (A > 8) {
        A += -9
    }
    if (B > 8) {
        B += -9
    }
    if (C > 8) {
        C += -9
    }
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
    A += 1
    B += 1
    C += 1
})
input.buttonsAB.onEvent(ButtonEvent.Click, function () {
    A = 0
    B = 1
    C = 2
})
let _1C = 0
let Color1C = 0
let _1B = 0
let Color1B = 0
let _1A = 0
let Color1A = 0
let C = 0
let B = 0
let A = 0
let list = [Colors.Blue, Colors.Green, Colors.Indigo, Colors.Orange, Colors.Pink, Colors.Yellow, Colors.Red, Colors.Violet, Colors.Orange]
let Main_Strip = light.createStrip(pins.A1, 24)
let Traveler = Main_Strip.range(0, 4)
let Traveler2 = Main_Strip.range(4, 4)
A = 0
B = 1
C = 2
forever(function () {
    Main_Strip.move(LightMove.Rotate, 1)
    pause(50)
})
forever(function () {
    Color1A = list[_1A]
    Color1B = list[_1B]
    Color1C = list[_1C]
    Main_Strip.setAll(Color1A)
    Traveler.setAll(Color1B)
    Traveler2.setAll(Color1C)
    _1A = A
    _1B = B
    _1C = C
})


Ha, I am so confused.

jonahlee
 
Posts: 11
Joined: Sat Feb 01, 2020 6:42 pm

Re: CPE and external Neopixel issues changing colors in arra

by jonahlee on Sun Feb 16, 2020 9:09 pm

Hmm, so I definitely have some code wrong as if I remove the second forever with the rotate 1, the colors are still pulsing even though they do change when I press the buttons.

jonahlee
 
Posts: 11
Joined: Sat Feb 01, 2020 6:42 pm

Re: CPE and external Neopixel issues changing colors in arra

by V2man on Sun Feb 16, 2020 11:01 pm


V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPE and external Neopixel issues changing colors in arra

by V2man on Thu Feb 20, 2020 2:09 am

Here's an example of an array I created.
Copy this code into the Java script of Makecode. Then switch to blocks.
Rearrange the each group of blocks so you can see what's going on. They tend to land one on top of the other in the translation from Java to Blocks.

Code: Select all | TOGGLE FULL SIZE
function STRIP0colors () {
    S0colors = [Colors.Red, Colors.Orange, Colors.Yellow, Colors.Green, light.rgb(0, 255, 255), Colors.Blue, Colors.Purple, Colors.Pink, light.rgb(128, 0, 64), Colors.White]
}
function STRIP1colors () {
    for (let index = 0; index <= strip1.length() - 1; index++) {
        S1colors[index] = light.hsv(20 * index, 255, 255)
    }
}
/**
 * CPX-Xstrip-Array
 */
let np = 0
let S1colors: number[] = []
let S0colors: number[] = []
let strip1: light.NeoPixelStrip = null
let strip0 = light.onboardStrip()
strip1 = light.createStrip(pins.A1, 12)
light.onboardStrip().setBrightness(20)
strip1.setBrightness(20)
let Tmin = 60
let Tmax = 80
STRIP0colors()
STRIP1colors()
forever(function () {
    light.onboardStrip().setAll(0x000000)
    np = 0
    for (let value0 of S0colors) {
        light.onboardStrip().setPixelColor(np, value0)
        pause(100)
        np = np + 1
    }
    strip1.setAll(0x000000)
    np = 0
    for (let value1 of S1colors) {
        strip1.setPixelColor(np, value1)
        pause(100)
        np = np + 1
    }
})

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPE and external Neopixel issues changing colors in arra

by V2man on Thu Feb 20, 2020 2:35 pm

Also while in Blocks use right click --> Format to separate groups of blocks to clarify what you are looking at.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPE and external Neopixel issues changing colors in arra

by jonahlee on Sat Apr 11, 2020 8:38 pm

Yea I know about the Neopixels page, and I made an array which seems to work as I can change the colors, but the pulsing instead of going around was my question. Your example doesn't have any examples of using the buttons to change colors so it doesn't help what I am trying to do at all.

Thanks though. Still trying to figure this out.

jonahlee
 
Posts: 11
Joined: Sat Feb 01, 2020 6:42 pm

Re: CPE and external Neopixel issues changing colors in arra

by jonahlee on Sat Apr 11, 2020 9:22 pm

So from what I am seeing I can only either change the color or rotate the colors on the neopixel. If I have changing the colors active I can only do that. or I can get it to rotate but then I can't change colors.

jonahlee
 
Posts: 11
Joined: Sat Feb 01, 2020 6:42 pm

Re: CPE and external Neopixel issues changing colors in arra

by BIS_Bro2 on Tue Apr 21, 2020 1:39 pm

I haven't programmed the CPB in Makecode yet; just now looking at it.
I don't know Javascript but from looking at the code, you have two "forever" loops. Once the code enters the first one (not sure how it picks which one yet - arrangement on screen maybe) unless you have provided a way to escape that loop, you are stuck in that "forever" loop forever.

What I do sometimes is take a piece of paper and read the code starting at the first line (Icon?). When a variable is first mentioned I write it on the paper. If it's assigned a value right then, I write the value next to it. If not, I put a question mark (?) to remind myself it may have some random value. When I come across it again and assign another value, I cross it off and write the new value.

The first thing I might try would be to arrange the code blocks left to right and then look at the Javascript. See which one generates code first. Re-arrange order and see if it agrees with what you thought.

Next try arranging top to bottom and check Javascript. Did that change the order of code?

I may do this first thing when I get my CPB set up and then figure out what icon/feature starts the CPB running.

Hope this helps

BIS_Bro2
 
Posts: 1
Joined: Mon Apr 13, 2020 2:36 pm

Please be positive and constructive with your questions and comments.