Strange Random Number
First post - so please be gentel with me!
Ive got a small bit of code, that sets a random number for Red, Green, Blue to output to a WS2812 LED, the code to output the RGB to the LED works as ive got random colours showing. However when I outout the values of Red, Green, Blue to the serial output, the Blue is a strange number:-
MyRed = 12
MyGreen = 41
MyBlue = 3119
MyRed = 85
MyGreen = 75
MyBlue = 21771
MyRed = 55
MyGreen = 80
MyBlue = 14094
MyRed = 68
MyGreen = 82
MyBlue = 17488
MyRed = 46
MyGreen = 34
MyBlue = 11809
MyRed = 71
MyGreen = 5
MyBlue = 18192
MyRed = 88
MyGreen = 21
MyBlue = 22550
MyRed = 48
MyGreen = 62
MyBlue = 12313
etc
The code is:-
#include "FastLED.h"
#define NUM_LEDS 100
#define DATA_PIN 5
#include <Arduino.h>
// Define the array of leds
CRGB leds[NUM_LEDS];
int MyRed; int MyGreen; int MyBlue; int MyStar;
void setup()
{
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
MyRed = 0; MyGreen = 0; MyBlue = 0;
Serial.begin (9600);
randomSeed(analogRead(0));
}
void loop()
{
for (int i = 0; i <= NUM_LEDS; i++)
{
MyRed = random(1, 100);
MyGreen = random(1, 100);
MyBlue = random(1, 100);
leds[i].setRGB(MyGreen, MyRed , MyBlue);
}
MyStar = random(NUM_LEDS);
leds[MyStar].setRGB(255, 255, 255);
FastLED.setBrightness(50);
FastLED.show();
String stringOne= String(MyRed, DEC);
Serial.println ("MyRed = " + stringOne );
stringOne= String(MyGreen, DEC);
Serial.println ("MyGreen = " + stringOne );
stringOne= String(MyBlue, DEC);
Serial.println ("MyBlue = " + stringOne );
Serial.println (" " );
delay(500);
}
The idea is that the LED's are a random colour, with one bright white (star).
Oddly, if I set MyBlue=0 insted of a random ( MyBlue = 0; // random(1, 100); )
Its MyGreen that changes to Zero:-
MyRed = 40
MyGreen = 0
MyBlue = 10303
MyRed = 22
MyGreen = 0
MyBlue = 5706
MyRed = 94
MyGreen = 0
MyBlue = 24162
MyRed = 36
MyGreen = 0
MyBlue = 9267
MyRed = 56
MyGreen = 0
MyBlue = 14362
MyRed = 52
MyGreen = 0
MyBlue = 13369
Im confused !!!!!!!!!
Just tried this:-
MyRed = 0;
MyGreen = 0;
MyBlue = random(1, 100);
leds*.setRGB(MyGreen, MyRed , MyBlue);*
and the LED's are different brightness's of blue, but the output is showing:
MyRed = 0
MyGreen = 41
MyBlue = 0
MyRed = 0
MyGreen = 38
MyBlue = 0
MyRed = 0
MyGreen = 93
MyBlue = 0
MyRed = 0
MyGreen = 46
MyBlue = 0
MyRed = 0
MyGreen = 25
MyBlue = 0
etc