Difference between revisions of "DIY Desk Lamp"

From Microduino Wiki
Jump to: navigation, search
(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...")
 
Line 48: Line 48:
 
==Programming==
 
==Programming==
 
===Required Program Block===
 
===Required Program Block===
*[[“Waiting” program block]]
+
*[["Waiting" program block]]
*[[“Crash” program block]]
+
*[["Crash" 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 “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.  
+
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 “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.  
+
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、
+
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?  
+
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.  
+
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?
+
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 cna have a try!
+
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 “crash” and “digital write”.  
+
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?
+
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.  
+
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 “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.  
+
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>
  

Revision as of 07:33, 28 September 2016


Outline

Anywhere table-lamp.jpg

Make a small desk lamp, and learn to control the on and off of it with switch.

Suitable kits: mCookie102, mCookie202, mCookie302, IBC


Module Bill

Module

Module Number Function
mCookie-Core 1 Core board
mCookie-USBTTL 1 Program download
mCookie-Hub 1 Sensor adapter plate
Crash 1 Crash sensor
LED 1 Single-color LED

Other Equipment

  • USB cable*1
  • Sensor cable*1
  • Sensor shell*1
  • Lego or other fixation structure
Anywhere table-lamp-module.jpg


Module Setup

Anywhere table-lamp-module—step.jpg
  • Assemble the modules and sensors:
    • Stick the red core module, USB upload module and green extension module together;
    • Connect the red LED to pin 6/7 of Hub;
    • Connect the crash sensor to pin 4/5 of Hub;
    • Insert one end of USB cable into USB to upload the modules, and connect the other to computer;


Programming

Required Program Block

Programming Thought

Press the crash sensor, the LED lights on; press again, the LED goes off.

Mixly-ctrl-table-lamp.jpg

Programming

1. Press the crash sensor, the LED lights on.
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.

Mixly-ctrl-table-lamp-code1.jpg

2. Press again, the LED goes off
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.

Mixly-ctrl-table-lamp-code2.jpg

3.Test the result:
Look at if it is as expected: press the switch, the light is on; press again, the light goes off. Repeat as this.

Q: Why is the switch flexible sometimes, and out of control now and then?
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.
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?
A: You can have a try!
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".

Mixly-ctrl-table-lamp-code3.jpg



Q: The switch is still out of control?
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.
Q: How to make the switch stable?
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.

Programming thought:
Every time the switch being pressed and released, add a delay program block to wait for the internal of the crash calm down, in order to make the switch able to control the LED.

Mixly-ctrl1-table-lamp.jpg

Programming
1. 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 lights up.

Mixly-ctrl4-table-lamp-code4.jpg

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.

Mixly-ctrl4-table-lamp-code5.jpg

Test the result:
Press, release, then the LED lights up; press, release, then the LED goes off. Repeat that, turning it on and off continuously. So that we can use the crash to control the light stably.
Set up a desk lamp on your own, put the switch and LED at the right place, and see whose lamp is the most beautiful one.

Anywhere table-lamp.jpg

Technical Specification

  • The product number of crash sensor: MSDS11
  • Digital signal input sensor
  • For details, please refer to Sensor-Crash.

Related Cases

FAQ