Joystick Lantern

来自Microduino Wikipedia
跳转至: 导航搜索
Language English

Objective

To control the lantern's color and brightness through Joystick.

Principle

Equipment

Module Number Function
Microduino-CoreUSB 1 Core board
Microduino-Sensorhub 1 Sensor pin board
Microduino-Colorled 1 Colored light
Microduino-Joystick 1 Joystick sensor
Microduino-BM 1 Battery management

Hardware Buildup

  • Setup 1:Connect CoreUSB to the computer, open program example, then select the right board and download program via serial port.

Joystick_led

  • Setup 2:Stack CoreUSB and Sensorhub.
  • Setup 3:Connect the colored light to the D6 pin of Sensorhub and Joystick sensor to A0 and A1.
Microduino-sensorhub rule.JPG

Software Debugging

Code Description

  • Color pre-set: " color_m[9][3]" (With nine kinds of color and users can change according to personal needs.)
  • Joystick controls pin description:
#define JoystickX_PIN A1
#define JoystickY_PIN A0
  • Select color on the X-axis
	  if (sensorValueY <= 10)
  {
    delay(500);
    num++;
    if (num > 8)
      num = 0;
  }
  else if (sensorValueY > 800)
  {
    delay(500);
    num--;
    if (num < 0)
      num = 8;
  }
  • Select brightness on the Y-axis.
if (sensorValueX <= 10)
  {
    delay(10);
    color_l++;
    if (color_l > 255)
      color_l = 255;
  }
  else if (sensorValueX > 800)
  {
    delay(10);
    color_l--;
    if (color_l < 0)
      color_l = 0;
  }
  • Light display
colorWipe(strip.Color(map(color_l, val_min, val_max, 0, color_m[num][0]), map(color_l, val_min, val_max, 0, color_m[num][1]), map(color_l, val_min, val_max, 0, color_m[num][2])));

Result

Choose color on the X-axis and brightness on the Y-axis. You can also build a beautiful shell with LEGO.

Video