3-Color LED Module(KY-016)

아두위키 : Arduwiki

This module consists of a 3-color LED, allowing control over each color with values ranging from 0 to 255.

Specifications

  • Operating Voltage: 5V
  • LED Diameter: 5mm
  • Common cathode type

Example Hardware

  • Arduino Board
  • Jumper Cables
  • KY-016 3-Color LED Module
  • Tactile Switch

Connections

Since analogWrite() is used, pins capable of PWM output, such as D9, D10, and D11, are used.

Arduino 3-Color LED Module Tactile Switch
GND - Connect
D8 Connect
D9 B
D10 G
D11 R

Example Code

This example makes the LED emit light in 6 different colors sequentially when the button is pressed.

const int ledR = 11;
const int ledG = 10;
const int ledB = 9;
const int btn = 8;
int btnFlg = 0;

void setup() {
  pinMode(btn, INPUT_PULLUP);
}

void loop() {
  if (btnChk() == 1) {
    brightness(0, 0, 0);
    delay(500);
    brightness(255, 0, 0);
    delay(500);
    brightness(0, 255, 0);
    delay(500);
    brightness(0, 0, 255);
    delay(500);
    brightness(255, 255, 0);
    delay(500);
    brightness(255, 0, 255);
    delay(500);
    brightness(0, 255, 255);
    delay(500);
    brightness(0, 0, 0);
  }
  delay(10);
}

void brightness(int r, int g, int b) {
  analogWrite(ledR, r);
  analogWrite(ledG, g);
  analogWrite(ledB, b);
}

int btnChk() {
  if (digitalRead(btn) == 0) {
    btnFlg = 1;
    return 0;
  }
  if (btnFlg == 1) {
    btnFlg = 0;
    return 1;
  }
  return 0;
}


Example Code Result