Make a multi-functional flashlight, which can be lighting, and the brightness is adjustable.
Suitable kits: mCookie102, mCookie202, mCookie302, IBC
- USB cable*1
- Sensor cable*1
- Sensor shell*1
- Lego or other fixation structure
- Assemble the modules and sensors together:
- Stick the red core modules, USB upload module and green extension module together;
- Connect the red LED to pin 6/7 of Hub;
- Connect the crash to pin 4/5 of Hub;
- Insert one end of USB cable into the USB upload module, and connect the other to computer;
Required Program Blocks
Press the switch, the light is the most bright; press again, the light gets dark; press the third time, the light goes off. Adjust the brightness of the flashlight through “switch”.
1. Switch 4 is pressed, then LED 6 emits strong light
Set the pin of "crash button" program block to 4, and the state to press; set the "analog output" pin to 6, and assign 255 to it; set delay to 1000ms.
2. Switch 4 is pressed, and the LED 6 emits weak light.
Set the pin of crash to 4, and the state to press; set the pin of program block of "analog write" to 6, and assign 50 to it; delay 1000ms.
3、Switch 4 is pressed, and the LED 6 goes off.
Set the pin of "crash button" program block to 4, and the state to press; set the pin of "analog write" program block to 6, and assign 0 to it; delay 1000ms.
4. So link the program blocks together, and choose the core and port to download program.
Test the result:
Each time you press the switch, the brightness of LED will change. Make a flashlight with Lego, and install the switch and LED in the right place. Pay attention to the shell should be suitable for carrying.
- The product number of the crash sensor: MSDS11
- Crash sensor is belong to digital signal input sensor.
- For details, please refer to Sensor-Crash