Coding external lights is a little different than programming the onboard NeoPixel LEDs. The LED Sequins don't change color, but you can make them flash on and off and even fade them in and out. To do that, you will be changing the voltage output from the pins you attached them to.
You can view, edit, and run the test code at the top of the page by going to this link, or click on the button below.
Then keep reading to find out how to put together your own external lights program in MakeCode!
To start, open up MakeCode, click on ADVANCED in the menu list, and the menu for PINS will appear.
When you click on PINS, you will see an assortment of blocks to choose from. Here's how to program a simple on/off action:
To simply turn an LED (or row of LEDs attached to the same finger) on and off, click on When you "write" to a pin, you are giving it instructions. Digital instructions have only two options, off and on. In this case, off is labeled as "low" and on is called "high." Click on the pin number and select the pin you want to program -- in this case, A2, which controls the light on the pinky finger. Next, click on
|
|
Now drag and drop a Change the number of milliseconds (ms) to make the light stay on as long as you like. In this case, it is set to 500 ms, or half a second. Finally, add another For testing purposes, add any play sound block. Then download and test your code to make sure the LED Sequin lights up!
|
|
If the first pin is working, repeat the process with the other pins, adding |
To set an external LED somewhere between "on" and "off" you can use an In the old days, you could change the amount of voltage just by turning a knob. With digital technology, the same effect is usually created by pulsing the voltage on and off repeatedly at a certain rate of speed. This is called pulse width modulation, or PWM. The Note that the In the example project here, the A1 pin was used for the touch control, so only the LED on pin A2 can be programmed to fade in and out. |
Troubleshooting
Test your soft circuit before inserting it into the masking tape hand. If an LED is not lighting up, check that:
- you set the correct pin number on the
digital write
oranalog write
block. - the LED is making a good connection with the conductive tape. Try pressing on it while the code is running to see if that's the problem. You can add more tape if needed. Or try moving the LED to a different spot.
- there are no short circuits between pieces of tape (or loose threads coming off the tape). Also check that the tape on the CPX board is only touching the pin or pad it is supposed to touch, and nothing else!
Bonus Code!
If you're interested in seeing how to use more advanced programming concepts like functions, variables, and CONTROL blocks to make LEDs turn on and off and fade while the theme from The Addams Family plays, click on this link or the button below.