農曆新年安排 - 農曆假期為1月19日(年廿八)至1月29日(初八),1月30日(初九)啟市。 受晶片供應影響,PI / micro:bit / Jetson供貨及價格較為浮動,敬請見諒。

KY-027 魔術光杯模組 Magic Light Cup Module

$15.00

貨號: KY-025 分類: ,

描述

KY-027 MAGIC LIGHT CUP MODULE

Arduino KY-027 Magic Light Cup Module is a set of two boards, each one has a led and a mercury tilt switch. Using PWM to drive the LEDs on each module you can achieve the effect of light being “magically” transferred from one module to the other when tilting them.

 

  • Arduino KY-027 Magic light cup module

Specifications

The KY-027 is a pair of modules, each one consist of a mercury switch, a led and a 10 kΩ resistor. Each board have a pins to control the switch, LED, power and ground.

Operating Voltage 3.3V to 5.5V
Board Dimensions 1.5cm x 3.6cm [0.6in x 1.4in]

Arduino KY-027 Connection Diagram

Connect each module using the following diagram.

KY-027 (A) Arduino
G GND
+ 5v
S 8
L 9
KY-027 (B) Arduino
G GND
+ 5v
S 7
L 6
click to enlarge

KY-027 Arduino Example Code

In this Arduino sketch we’ll use both KY-027 modules to create the magic light cup effect. The mercury switches in each module provide a digital signal that is used to regulate the brightness of the LEDs using using PWM. Tilting the modules will decrease the brightness on one module while increasing it on the other one, creating the illusion of light magically passing from one module to the other.

 

int ledPinA = 9;
int switchPinA = 8;
int switchStateA = 0;
int ledPinB = 6;
int switchPinB = 7;
int switchStateB = 0;
int brightness   = 0;

void setup() 
{
  pinMode(ledPinA, OUTPUT); 
  pinMode(ledPinB, OUTPUT);  
  pinMode(switchPinA, INPUT); 
  pinMode(switchPinB, INPUT);
}

void loop() 
{
  switchStateA = digitalRead(switchPinA);
  if (switchStateA == HIGH && brightness != 255)
  { 
   brightness ++;
  } 
  switchStateB = digitalRead(switchPinB);
  if (switchStateB == HIGH && brightness != 0)
  { 
   brightness --;
  } 
  analogWrite(ledPinA, brightness);  //  A slow fade out
  analogWrite(ledPinB, 255 - brightness);  // B slow bright up
  delay(20);
}

商品評價

目前沒有評價。

只有註冊並且購買過商品的顧客才能撰寫評價。