Function of the Module
Equipment
- Other Hardware Equipment
- One USB cable
- Two sensor cables
Example 1: Long-press & Short-press Function
Overview
To detect the key is long pressed or short pressed, which can be distinguished by checking the returned results in the serial monitor.
Hardware Buildup
- Setup 1:Connect the interface on the back of the Crash to D6 port of the Hub, which is the control pin of the Crash and users can change that by yourselves.
- Setup 2:Connect the CoreUSB, Hub and Crash together to the computer with a USB cable.
Mixly Programming
- Step1:Open Mixly software and you'll find "Light Control" in "Executer" under the item of "Microduino".
- Step2:Drag out the item of "Key". Since the hardware connection is connected to pin 6 while the pin 4 is the default one to be set after dragging out, you need to change "4' to 6". If you don't want to change, you can also connect the key to the pin 4 of the Hub.
- Step3:Since we use the serial monitor, we need to find "Serial communication" from "Communication" item.
- Step4:Serial communication description.
- Step5:Fill in the content you want to print in the item of "Text", which must be English characters.
- Step5:Since the long-press is always triggered, you can use system "Timer" to delay time, which can be found in "Executer".
- Step6:System "Timer" description.
- Step7:Overall code description.
Debugging
Step1:Select the right board card(Core USB 32U4) and COM port(Recognized automatically by default).
Step2:Open the serial monitor.
Step3:Make sure the serial baud rate is the same with the pre-set one.
Step4:Short press or long press the key and you'll see "short" or "long" pressed in the serial monitor every 1s.
Experiment 2: State Turnover Function
Overview
Each time you press down a key, the status will turn over once. Like a desk lamp, when you press down, it turns on. And press one more time, it'll turn off. There're only two states. We can see the result through the serial monitor. Pressing down means "ON" (print "ON" in the serial monitor)and one more time, means "OFF"("OFF" printed in the serial monitor).
Hardware Buildup
Mixly Programming
- Step1:Open Mixly software and find the relevant Serial items in "Communication" since we need the serial monitor to observe results.
- Step2:Since there're only two states, you can introduce Boolean variable to achieve that, which can be found in "Variable".
- Step3: Drag out the item of "Key". Since the hardware connection is connected to pin 6 while the pin 4 is the default one to be set after dragging out, you need to change "4' to 6".
- Step4:Judge the status of the key. Make Boolean value as its own "No" value, and every time you press the key, the status of the Boolean value will turn over once and there is a loop between "True" and "False". Therefore, you can print "ON" or "OFF" by judging "True" or "False".
- Step5:Need to use logic parameter: False. Found it in the "Logic" item.
- Step6:Next, we need to judge the "True" or "False" value of the Boolean variable. You can find condition statement in "Control".
- Condition judgment description.
- Step7:Find out "Serial Communication" item and the "Text" item, make judgment according to Boolean variable, therefore, print out "ON" or "OFF".
- Step8:Overall code description.
Debugging
Step1:Select the right board card(Core USB 32U4) and COM port(Recognized automatically by default).
Step2:Open the serial monitor.
Step3:Make sure the serial baud rate is the same with the pre-set one.
Step4:Short press the key once and you'll see "ON' printed in the serial monitor. Press down again and you'll see "OFF" printed.
Extension
By changing the serial port print to the colored lights, you can DIY a little desk lamp.
|