Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:iot-open:practical:hardware:rtu:robotnest:rgb-led [2025/07/30 08:55] – created kivilands6en:iot-open:practical:hardware:rtu:robotnest:rgb-led [2025/07/30 09:05] (current) kivilands6
Line 2: Line 2:
 This scenario presents how to handle the brightness control of the tri-coloured LEDs. Both LEDs are electrically bound and cannot be controlled independently. Those LEDs have 3 colour channels, controlled independently: R (Red), G (Green) and B (Blue). Mixing of those colours creates other ones, such as pink and violet. Each R G B channel can be controlled with a separate GPIO to switch it on or off or control brightness using a PWM signal, as presented in this tutorial. This scenario presents how to handle the brightness control of the tri-coloured LEDs. Both LEDs are electrically bound and cannot be controlled independently. Those LEDs have 3 colour channels, controlled independently: R (Red), G (Green) and B (Blue). Mixing of those colours creates other ones, such as pink and violet. Each R G B channel can be controlled with a separate GPIO to switch it on or off or control brightness using a PWM signal, as presented in this tutorial.
  
 +====== Step 1 =====
 +Define the necessary pins and functions:
 +<code>
 +/* RGB LEDS */
 +#define RED_PIN   14
 +#define GREEN_PIN 15
 +#define BLUE_PIN  16
 +void setRGB(int red, int green, int blue);
 +</code>
 +====== Step 2 =====
 +Define pins as output:
 +<code>
 +void setup() {
 +  Serial.begin(152000);
 +
 +  pinMode(RED_PIN, OUTPUT);
 +  pinMode(GREEN_PIN, OUTPUT);
 +  pinMode(BLUE_PIN, OUTPUT);
 +}
 +</code>
 +====== Step 3 =====
 +Add a function at the end of the code:
 +<code>
 +void setRGB(int red, int green, int blue) {
 +  analogWrite(RED_PIN, green);
 +  analogWrite(GREEN_PIN, blue);
 +  analogWrite(BLUE_PIN, red);
 +}
 +</code>
 +====== Step 4 =====
 +Write some code for the LED's (circle through red, green, blue light):
 +<code>
 +void loop() {
 +  setRGB(255, 0, 0);
 +  delay(1000);
 +  setRGB(0, 255, 0);
 +  delay(1000);
 +  setRGB(0, 0, 255);
 +  delay(1000);
 +}
 +</code>
en/iot-open/practical/hardware/rtu/robotnest/rgb-led.1753865719.txt.gz · Last modified: 2025/07/30 08:55 by kivilands6
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0