Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB1 TYWU. Devices Dip Switch (4 Switches) Triple Output LED (RGB) –Common Cathode.

Similar presentations


Presentation on theme: "LAB1 TYWU. Devices Dip Switch (4 Switches) Triple Output LED (RGB) –Common Cathode."— Presentation transcript:

1 LAB1 TYWU

2 Devices Dip Switch (4 Switches) Triple Output LED (RGB) –Common Cathode

3 Specification Controller Luminance (Blink Mode)

4 Photo Arduino

5 Instruction analogWrite –http://www.arduino.cc/en/Reference/AnalogW rite

6 .pde #define SW1 7 #define SW2 6 #define SW3 5 #define SW4 4 #define SW1 7 #define SW2 6 #define SW3 5 #define B 9 // Analog Pin 0 #define G 10 // Analog Pin 1 #define R 11 // Analog Pin 2 #define BLINK_FACTOR 30 // Analog Pin 2

7 .pde int cnt = 0; int luma = 1; void setup() { pinMode(SW1, INPUT); pinMode(SW2, INPUT); pinMode(SW3, INPUT); pinMode(SW4, INPUT); pinMode(B, OUTPUT); pinMode(G, OUTPUT); pinMode(R, OUTPUT); digitalWrite(SW1, HIGH); // turn on pullup resistors digitalWrite(SW2, HIGH); // turn on pullup resistors digitalWrite(SW3, HIGH); // turn on pullup resistors digitalWrite(SW4, HIGH); // turn on pullup resistors Serial.begin(9600); }

8 .pde void loop() { if(digitalRead(SW1)==HIGH) cnt = (cnt + 1) % BLINK_FACTOR; if(digitalRead(SW2)==HIGH) analogWrite(B, luma); else analogWrite(B, 0); if(digitalRead(SW3)==HIGH) analogWrite(G, luma); else analogWrite(G, 0); if(digitalRead(SW4)==HIGH) analogWrite(R, luma); else analogWrite(R, 0); if(cnt == 0 && digitalRead(SW1)==HIGH) luma=luma * 2; if(luma > 128) luma = 1; Serial.print(luma, DEC); Serial.println(""); }

9 Exercise Add another LED Generate the Complement Color of the Original LED


Download ppt "LAB1 TYWU. Devices Dip Switch (4 Switches) Triple Output LED (RGB) –Common Cathode."

Similar presentations


Ads by Google