Difference between revisions of "DIY Desk Lamp"
(Created page with "{| style="width: 1000px;" |- | ==Outline== 600px|center Make a small desk lamp, and learn to control the on and off of it with switch. Su...") |
(→Required Program Block) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 48: | Line 48: | ||
==Programming== | ==Programming== | ||
===Required Program Block=== | ===Required Program Block=== | ||
− | *[[ | + | *[["Waiting" program block]] |
− | *[[ | + | *[["Crash button" program block]] |
===Programming Thought=== | ===Programming Thought=== | ||
Line 57: | Line 57: | ||
'''1. Press the crash sensor, the LED lights on.''' | '''1. Press the crash sensor, the LED lights on.''' | ||
<br> | <br> | ||
− | Set the pin of | + | Set the pin of "crash" program block to 4, and the state to press; set the pin of "digital write" program block to 6, and the state to high; that is controlling the LED to light up after pressing the crash sensor. |
[[File:mixly-ctrl-table-lamp-code1.jpg|600px|center]] | [[File:mixly-ctrl-table-lamp-code1.jpg|600px|center]] | ||
'''2. Press again, the LED goes off''' | '''2. Press again, the LED goes off''' | ||
<br> | <br> | ||
− | Set the pin of the | + | Set the pin of the "crash" program block to 4, and the state to press; set the pin of "digital write" to 6, and the state to low; that is controlling the LED to go off after the crash being pressed. |
[[File:mixly-ctrl-table-lamp-code2.jpg|600px|center]] | [[File:mixly-ctrl-table-lamp-code2.jpg|600px|center]] | ||
− | + | 3.'''Test the result:''' | |
− | '''Test the result:''' | ||
<br> | <br> | ||
Look at if it is as expected: press the switch, the light is on; press again, the light goes off. Repeat as this. | Look at if it is as expected: press the switch, the light is on; press again, the light goes off. Repeat as this. | ||
<br> | <br> | ||
<br> | <br> | ||
− | + | Q: Why is the switch flexible sometimes, and out of control now and then? | |
<br> | <br> | ||
− | + | A: This is because the thinking speed of the core module is very fast, the moment you press the crash, the program judging switch stays down all the time, and the program has been executed millions of times. At this point, LED has been on and off for many times, which is invisible,that is why you think it is out of control. | |
<br> | <br> | ||
− | + | Q: I get it. If I set the program to wait for the crash to be pressed, and then wait for it to be released, is this OK? | |
<br> | <br> | ||
− | + | A: You can have a try! | |
<br> | <br> | ||
− | Press the crash down, and then release, to turn the LED on. Repeat it to make turn the LED off. Modify the parameters of program block | + | Press the crash down, and then release, to turn the LED on. Repeat it to make turn the LED off. Modify the parameters of program block "crash" and "digital write". |
[[File:mixly-ctrl-table-lamp-code3.jpg|600px|center]] | [[File:mixly-ctrl-table-lamp-code3.jpg|600px|center]] | ||
<br> | <br> | ||
<br> | <br> | ||
− | + | Q: The switch is still out of control? | |
<br> | <br> | ||
− | + | A: Because the "crash" belongs to the mechanical keys, at the moment of being pressed or released, the internal metal chip will shake many times, the program will detect the crash has been pressed and released many times, and the program will be executed continuously. Actually, in this program, the LED has been turned om many times which can't be seen. | |
<br> | <br> | ||
Q: How to make the switch stable? | Q: How to make the switch stable? | ||
<br> | <br> | ||
− | A: In fact, only a | + | A: In fact, only a "delay" can resolve this problem. At the time of pressing the switch, delay 100ms(make the program pause for 100ms), to wait for the internal shock of the crash subside, and eliminate the jitter of the crash. |
<br> | <br> | ||
Line 113: | Line 112: | ||
==Related Cases== | ==Related Cases== | ||
− | *'''[[Flashlight]]''' | + | *'''[[Multi-Functional Flashlight]]''' |
*'''[[Door Bell]]''' | *'''[[Door Bell]]''' | ||
− | *'''[[ | + | *'''[[Music Painting]]''' |
==FAQ== | ==FAQ== | ||
|} | |} |
Latest revision as of 10:25, 9 October 2016
ContentsOutlineMake a small desk lamp, and learn to control the on and off of it with switch. Suitable kits: mCookie102, mCookie202, mCookie302, IBC
Module BillModule
Other Equipment
Module Setup
ProgrammingRequired Program BlockProgramming ThoughtPress the crash sensor, the LED lights on; press again, the LED goes off. Programming1. Press the crash sensor, the LED lights on.
2. Press again, the LED goes off
3.Test the result:
Programming thought:
Programming
2. Every time the switch being pressed and released, add a delay, to wait for the internal shock of the crash to calm down. Press, release, then the LED goes off. Test the result:
Technical Specification
Related CasesFAQ |