Project10.Magical Light Cup ============================= Description ------------ Magic light cup module is able to interact with ARDUINO. The principle is based on PWM dimming.The mercury switch on the module can provide a digital signal and trigger PWM regulation. The brightness of two modules will be changed together through the program design, finally you can see the changing effect that two set of cups are pouring the light. Specification -------------- - Supply Voltage: 3.3V to 5V - Interface: Digital Connect -------- .. image:: /img/connect/10_bb.png Code ----- .. code-block:: c int LedPinA = 5; int LedPinB = 6; int ButtonPinA = 7; int ButtonPinB = 4; int buttonStateA = 0; int buttonStateB = 0; int brightnessA = 0; int brightnessB= 255; void setup() { Serial.begin(9600); pinMode(LedPinA, OUTPUT); pinMode(LedPinB, OUTPUT); pinMode(ButtonPinA, INPUT); pinMode(ButtonPinB, INPUT); } void loop() { buttonStateA = digitalRead(ButtonPinA); if (buttonStateA == HIGH && brightnessA != 255) { brightnessA ++; } if (buttonStateA == LOW && brightnessA != 0) { brightnessA --; } analogWrite(LedPinB, brightnessA); Serial.print(brightnessA); Serial.print(" "); buttonStateB = digitalRead(ButtonPinB); if (buttonStateB == HIGH && brightnessB != 0) { brightnessB --; } if (buttonStateB == LOW && brightnessB != 255) { brightnessB++; } analogWrite(LedPinA, brightnessB); Serial.println(brightnessB); delay(5); } Phenomenon ----------- .. image:: /img/phenomenon/10.jpg