Goouuu-S1 ESP8266 RGB led examples

In a previous post we looked at the Goouuu-S1 ESP8266 , on the board you will have seen that there is an RGB led

The board uses the following pins for the LED

int redpin = 12; // select the pin for the red LED

int bluepin = 14; // select the pin for the blue LED

int greenpin =13; // select the pin for the green LED

Code Examples

[codesyntax lang=”cpp”]

int redpin = 12; // select the pin for the red LED
int bluepin = 14; // select the pin for the blue LED
int greenpin =13; // select the pin for the green LED

int val=0;

void setup () 
{
  pinMode (redpin, OUTPUT);
  pinMode (bluepin, OUTPUT);
  pinMode (greenpin, OUTPUT);
  Serial.begin (9600);
}

void loop () 
{
  for (val=255; val>0; val--)
  {
    analogWrite (redpin, val);
    analogWrite (bluepin, 255-val);
    analogWrite (greenpin, 128-val);
    delay (50);
  }
  for (val = 0; val <255; val++)
  {
    analogWrite (redpin, val);
    analogWrite (bluepin, 255-val);
    analogWrite (greenpin, 128-val);
    delay (50);
  }
  Serial.println (val, DEC);
}

[/codesyntax]

 

And another example

 

[codesyntax lang=”cpp”]

int redpin = 12; // select the pin for the red LED
int bluepin = 14; // select the pin for the blue LED
int greenpin =13; // select the pin for the green LED

int val=0;

void setup () 
{
  pinMode (redpin, OUTPUT);
  pinMode (bluepin, OUTPUT);
  pinMode (greenpin, OUTPUT);
  Serial.begin (9600);
}

void loop () 
{
  LEDOff();
  REDOn();
  LEDOff();
  GREENOn();
  LEDOff();
  BLUEOn();
}

void LEDOff()
{  
  digitalWrite(redpin,HIGH);
  digitalWrite(greenpin, HIGH);
  digitalWrite(bluepin, HIGH);
  delay (500);
}

void REDOn()
{
  digitalWrite(redpin,LOW);
  digitalWrite(greenpin, HIGH);
  digitalWrite(bluepin, HIGH);
  delay (500);
}

void GREENOn()
{
  digitalWrite(redpin,HIGH);
  digitalWrite(greenpin, LOW);
  digitalWrite(bluepin, HIGH);
  delay (500);
}

void BLUEOn()
{
  digitalWrite(redpin,HIGH);
  digitalWrite(greenpin, HIGH);
  digitalWrite(bluepin, LOW);
  delay (500);
}

[/codesyntax]

 

2 COMMENTS