Simple Demo of Led RGB

Updated: 1 minute read

Simple Demo of Led RGB

Demonstration

  • Hardware Simulation

Introduction

See Introduction of Internet of the Things in previous article.

Objective

Demonstrate how to use an RGB led. That is all!

Software

Hardware

  • Arduino UNO

  • Breadboard mini

  • Led RGB

  • Resistances

Code

  • Simple_Demo_of_Led_RGB

    /*
    led_rgb.c 
    v0.0.1 - 2019-02-20 - nelbren.com
    */ 
    int ledRed =   13;
    int ledBlue =  12;
    int ledGreen = 11;
    
    void setup(void){
      Serial.begin(9600);
      Serial.println("");
        
      pinMode(ledGreen, OUTPUT);
      digitalWrite(ledGreen, HIGH);
    
      pinMode(ledBlue, OUTPUT);
      digitalWrite(ledBlue, HIGH);
    
      pinMode(ledRed, OUTPUT);
      digitalWrite(ledRed, HIGH);
    }
    
    void red(void) {
      digitalWrite(ledRed, HIGH);
      digitalWrite(ledGreen, LOW);
      digitalWrite(ledBlue, LOW);
      Serial.println("  -> RED!");
    }
    
    void green(void) {
      digitalWrite(ledGreen, HIGH);
      digitalWrite(ledRed, LOW);
      digitalWrite(ledBlue, LOW);
      Serial.println("  -> GREEN!");
    }
    
    void yellow(void) {
      digitalWrite(ledRed, HIGH);
      digitalWrite(ledGreen, HIGH);
      digitalWrite(ledBlue, LOW);
      Serial.println("  -> YELLOW!");
    }
    
    void blue(void) {
      digitalWrite(ledBlue, HIGH);
      digitalWrite(ledRed, LOW);
      digitalWrite(ledGreen, LOW);
      Serial.println("  -> BLUE!");
    }
    
    void white(void) {
      digitalWrite(ledBlue, HIGH);
      digitalWrite(ledRed, HIGH);
      digitalWrite(ledGreen, HIGH);  
      Serial.println("  -> WHITE!");
    }
    
    void black(void) {
      digitalWrite(ledRed, LOW);
      digitalWrite(ledGreen, LOW);
      digitalWrite(ledBlue, LOW);
      Serial.println("  -> BLACK!");
    }
    
    void demo(void) {
      Serial.println("DEMO:");
      for(int i = 0; i < 6; i++) {
        switch (i) {
          case 0: red(); break;
          case 1: green(); break;
          case 2: yellow(); break;
          case 3: blue(); break;
          case 4: white(); break;
          case 5: black(); break;
        }
        delay(1000);
      }
      Serial.println("");
    }
    
    void loop(void){
      demo();
    }