Demo Simple de Led RGB

Actualizado: 1 minuto de lectura

Demo Simple de Led RGB

Demostraci贸n

  • Simulaci贸n de Hardware

Introducci贸n

Ver Introducci贸n del Internet de las Cosas en art铆culo anterior.

Objetivo

Demostrar como utilizar un led RGB. 隆Eso es todo!

Software

Hardware

  • Arduino UNO

  • Breadboard mini

  • Led RGB

  • Resistencias

C贸digo

  • 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();
    }