Hello all,
I am very new to both the forum and arduino in general. I have tried out many different sketches to get my rgb led to randomly choose and stay on a colour each time a button is pressed. Instead it continuously cycles through different colours only pausing briefly when the button is pushed. I hope someone can help me, my project is due next week and I am so lost.
// Variables to assign outputs to each color
const int ledRedPin = 10;
const int ledGreenPin = 9;
const int ledBluePin = 8;
// Variable to assign the pin button
const int buttonPin = 2;
// Variables that control the intensity of each color
int red;
int green;
int blue;
// Variable for the state of the button (HIGH or LOW)
int butState;
void setup () {
pinMode (ledRedPin, OUTPUT);
pinMode (ledGreenPin, OUTPUT);
pinMode (ledBluePin, OUTPUT);
pinMode (buttonPin, INPUT);
// initialize colours
red = random(256);
green = random(256);
blue = random (256);
}
void loop() {
// output led
digitalWrite (ledRedPin, red);
digitalWrite (ledGreenPin, green);
digitalWrite (ledBluePin, blue);
butState = digitalRead (buttonPin);
// change colour values
if (butState == HIGH) {
//randomSeed();
red = random(256);
green = random(256);
blue = random (256);
}
}