mercredi 10 juin 2020

Generate random numbers from given random array values Arduino program C++

I am trying to generate random output for the leds from the given values in the array I created but it does not work, I found this online and they said do it like below but it doesn't do anything. The programme should get a random value from the array.

int randomArray[4] = { 0,85,170,255 };




void setup() {

    Serial.begin(9600);
    pinMode(red, OUTPUT);
    pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
    pinMode(RLed, OUTPUT);
    pinMode(YLed, OUTPUT);
    pinMode(GLed, OUTPUT);
    randomSeed(millis());
    for (byte i = 0; i < 5; i = i + 1) {
        Serial.println(randomArray[i]);
    }
}

void loop() {

    redvalue = random();
    bluevalue = random();
    greenvalue = random();
    Serial.println(redvalue);
    Serial.println(bluevalue);
    Serial.println(greenvalue);
    analogWrite(red, redvalue);
    analogWrite(blue, bluevalue);
    analogWrite(green , greenvalue);
    analogWrite(RLed, redvalue);
    analogWrite(YLed, bluevalue);
    analogWrite(GLed, greenvalue);
    delay(1000);
}



Aucun commentaire:

Enregistrer un commentaire