Random Color display on the rgb light on arduino wifi uno

I have made the code work for a normal rgb led but i cant do it for the rgb led on the arduino uno wifi rev 2
This is my code

#include <WiFiNINA.h>
#include <utility/wifi_drv.h>
const int redPin = 25;
const int greenPin = 26;
const int bluePin = 27;

void setup() {
  WiFiDrv::pinMode(25, OUTPUT); //define green pin
  WiFiDrv::pinMode(26, OUTPUT); //define red pin
  WiFiDrv::pinMode(27, OUTPUT); //define blue pin
}

void loop() {
  analogWrite(redPin, random(0,1000));
  analogWrite(greenPin, random(0,1000));
  analogWrite(bluePin, random(0,1000));

  delay(100);
}

Thank you :slight_smile: goodbye

Start by writing a fixed value to each of the LED pin such as 128 for each.. Does the LED light up and if so, does changing the values written to 0, 0, and 255 change the colour of the LED ?

Apart from any other problems with your sketch, random(2, 1000) will return a value between 0 and 999 but the maximum value used by analogWrite() is 255

For testing I also suggest that you increase the delay() to 1000 to give more time to see the RGB colour

With the code i didn't mean to have 1000 it was originally 255, I was just testing. My current code does say 255
I have made it so that i can do a rgb color switch.
I also have made it with another external rgb light, it will choise random

What RGB led? I can't find any mention of it on the product page...

I never saw it metioned on the website ever but i plugged mine in and it lit up.

Apparently it's connected to the wi-fi chip, not the atmega chip:

The problem with your sketch is that you can't use the standard analogWrite() function to control the led.

  analogWrite(redPin, random(0,1000));
  analogWrite(greenPin, random(0,1000));
  analogWrite(bluePin, random(0,1000));

should be like this:

  WiFiDrv::analogWrite(redPin, random(0,255));
  WiFiDrv::analogWrite(greenPin, random(0,255));
  WiFiDrv::analogWrite(bluePin, random(0,255));

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.