Key-press

From Microduino Wiki
Revision as of 09:44, 13 September 2016 by Fengfeng (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Function of the Module

Equipment

Module Number Function
mCookie-CoreUSB 1 Core board
mCookie-Hub 1 Sensor pin board
Microduino-Crash 1 Crash sensor
Microduino-Color LED 1 Colored LED
  • Other Hardware Equipment
    • One USB cable
    • Two sensor cables
Crash-module.jpg

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.
MCookie-Crash-sensor.JPG
  • Setup 2: Connect the CoreUSB, Hub and Crash together to the computer with a USB cable.
MCookie-Crash-pc.JPG

Mixly Programming

  • Step1: Open Mixly software and you'll find "Light Control" in "Executer" under the item of "Microduino".
Mixly-Crash.JPG
  • 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.
Mixly Serial.jpg
  • Step4: Serial communication description.
  • Step5: Fill in the content you want to print in the item of "Text", which must be English characters.
Mixly text.jpg
  • Step6: Since the long-press is always triggered, you can use system "Timer" to delay time, which can be found in "Executer".
Mixly millis.jpg
  • Step7:System "Timer" description.
  • Step8:Overall code description.

Debugging

Step1: Select the right board card(Core USB 32U4) and COM port(Recognized automatically by default).

Mixly board COM.jpg

Step2: Open the serial monitor.

Mixly COMXX.jpg

Step3: Make sure the serial baud rate is the same with the pre-set one.

Mixly COMXX ok.jpg

Step4: Short press or long press the key and you'll see "short" or "long" pressed in the serial monitor every 1s.

Mixly Serial shortlong.jpg

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

  • Same with【Example 1】

Mixly Programming

  • Step1: Open Mixly software and find the relevant Serial items in "Communication" since we need the serial monitor to observe results.
Mixly Serial.jpg
  • Step2: Since there're only two states, you can introduce Boolean variable to achieve that, which can be found in "Variable".
  • "Variable" description.
  • 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.
  • "False" description.
  • 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).

Mixly board COM.jpg

Step2: Open the serial monitor.

Mixly COMXX.jpg

Step3: Make sure the serial baud rate is the same with the pre-set one.

Mixly COMXX ok.jpg

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.

Mixly Serial boolean.jpg

Extension

By changing the serial port print to the colored lights, you can DIY a little desk lamp.