
Magic Light Cup Module for Arduino
Introduction
This module contains two part, one is ball switch, the other is red led. Basing on these two
part, we can make a project like a magic cup.
Specification
Operation voltage: 3.3V to 5V
4Pin
2 Pinout
Signal output pin, used for the mercury
switch is active or not
L Input pin for the red led
+(middle pin) Power
Ground
3.Example
This example shows you how to use this module, connection as below, and upload the
sketch, see how it will go~

Example code :
******Code begin******
int LedPinA = 3;
int LedPinB = 6;
int ButtonPinA = 4;
int ButtonPinB = 7;
int buttonStateA = 0;
int buttonStateB = 0;
int brightness = 0;
void setup ()
{
pinMode (LedPinA, OUTPUT);
pinMode (LedPinB, OUTPUT);
pinMode (ButtonPinA, INPUT);
pinMode (ButtonPinB, INPUT);
}
void loop ()
{
buttonStateA = digitalRead (ButtonPinA);
if (buttonStateA == LOW &&brightness!= 255)
{
brightness=brightness+5;
}
analogWrite (LedPinA, brightness); //
analogWrite (LedPinB, 255-brightness);//
delay (200);
buttonStateB = digitalRead (ButtonPinB);
if (buttonStateB == LOW &&brightness>= 255)
{

brightness=0;
analogWrite (LedPinA, brightness); // A few Guan Yuan (ii) ?
analogWrite (LedPinB, 255-brightness);// B Yuan (ii) a few Bang ?
delay (1000);
}
//brightness=brightness-5;
}
******Code End******