Force Sword

From Microduino Wiki
Jump to: navigation, search

Outline

Anywhere sword.jpg

Let's make a force sword, which will light up gradually when we hold the hilt.
Suitable kits: mCookie302, IBC


Module Bill

Module

Module Number Function
mCookie-Core 1 Core board
Battery box 1 Program download and power supply
mCookie-Hub 1 Sensor adapter plate
Touch sensor 1 Detect the touch
ColorLED 2 Color LED

Other Equipment

  • USB cable*1
  • Sensor wire*3
  • Sensor shell*1
  • Lego or other fixation structure
Anywhere sword-module.jpg

Module Setup

Setup

Anywhere sword-step.jpg
  • Assemble the modules and sensors:
    • Stick the red core module, battery base and green extension module together;
    • Connect the 2 color LEDs to pin 6/7 of Hub respectively;
    • Connect the touch sensor to pin 4/5 of Hub.
    • Insert one end of USB cable into the battery base, and connect the other to computer.

Programming

Required Program Blocks

Programming Thought

ColorLED prepare, wait for the touch sensor to be pressed, and make the "every time" program block light up gradually.

Mixly-ctrl-sword.jpg

Start To Program

ColorLED prepare, wait for the touch sensor to be pressed.

Mixly-ctrl-sword-code.jpg

Use "every time" to make the two LEDs light up gradually.
Define the variable i to the value of the red light of the color LED, and it increases from 0 to 255, by 1 each time; the red light values of LED 1, 2 vary with the change of i.
Delay 4s, to make the LED light up gradually, and the change is gentle, 4×255 times≈1s. After pressing the touch sensor, the force sword will arrive the brightest in around 1s.

Mixly-ctrl-sword-code1.jpg

Test the result
After upload, press the touch sensor, and the red LED will become brighter gradually, and arrive the brightest in around 1s. The force sword is completed.

Anywhere sword.jpg


Q: I find when the touch button is pressed, it can repeat the process of being on continuously; if I want the light to go off gradually, what should I do?
A: When the touch button is released, make the light go off gradually.

Release the touch sensor, the two color LEDs bbecome dark gradually.
Define variable i to the value of the red light of the color LED, and decrease from 255 to 0 gradually, by 1 each time and go off gradually. The force sword will completely be off in around 1s.

Mixly-ctrl-mic light-code2.jpg


Technical Specification

  • The product number of color LED: MSDL11
  • APT library is required to drive.
  • For details about color LED, please refer to Sensor-Color LED.
  • For details about touch sensor, please refer to Sensor-Touch Button.

Related Cases

FAQ