Let's make a landscape lamp, which has many colors.
Suitable kits: mCookie302, IBC
- USB cable*1
- Sensor cable*3
- Lego shell*1
- Lego or other fixation structure
Learn about the Color LED
Full-color LED, can emit light of any color. Many of it can be cascaded together.
The color LED has two interfaces, which are labeled "IN" and "OUT" respectively. For example, 2 color LEDs are needed now, and the control pin should be connected to pin 6/7 of Hub;
It should be paid attention to here that when connect the LED 1 from the pin 6/7 of Hub, it should be connected to the IN port of the LED 1, and when connect the LED 2, you should connect to the OUT port of LED 1 and the IN port of LED 2.
Difference between the crash sensor and touch sensor
The crash sensor converts the mechanical quantity into electricity, and the touch sensor converts the capacitance into electricity. Being pressed, the crash sensor will produce mechanical dither, so you should add delay to the program to eliminate the dither judge.
Being pressed, the touch sensor hasn't mechanical dither, so you needn't to add delay to the program. Our hands and touch sensors all have static electricity, so the touch sensor can induce the approaching of our hands and other conductive objects.
- Assemble the modules and sensors:
- Stick the red core module, battery base and green extension module together;
- Connect the full-color LED to pin 6/7 of Hub（pay attention to that connect the IN of the first LED to the sensor adapter plate, and connect the OUT to IN of the second LED）;
- Connect the touch sensor to pin 4/5 of Hub;
- Insert one end of USB into the battery base, and connect the other to computer;
Required Program Blocks
＊The first time pressing the touch button, the two color LEDs change into red;
＊The second time pressing the touch button, the two color LEDs change into blue;
＊The third time pressing the touch button, the two color LEDs go off.
Start to Programming
1. The first time you press the touch sensor, the two full-color LED change into red.
Because there are totally 2 full-color LEDs to use, set the LED number of "ColorLED prepare" to 2, and the control pin to 6. After the touch sensor is pressed, LED 1 and 2 are on red; delay 1000ms to release.
2. The second time pressing the touch button, the two color LEDs change into blue.
3.The third time pressing the touch button, the two color LEDs go off..
Test the result
After upload, press the touch sensor, and the full-color LED will change among red, blue, and off three states. In this way, we have completed the program of the landscape lamp.
- Product number of color LED: MSDL11
- You will use API library to drive.
- For details, please refer to Sensor-Color LED
- Q: How many color LEDs can be supported at most in cascade?
- A: Under the condition that the power supply supports, 1024 at most. Too many will result in insufficient power supply, and the power should be strengthened.