Led Random Color Delay Value Problem


can point out issue in code doesnt work properly. after sent value delay of how fast led switches color should switch led color stays constant. ideas appreciated :)

code: [select]
const int redpin = 3;
const int greenpin = 5;
const int bluepin = 6;
 
int red1 = 0;
int green1 = 0;
int blue1 = 0;
int delayvalue = 0;
 
void setup() {
  serial.begin(9600);
  pinmode(redpin, output);
  pinmode(greenpin, output);
  pinmode(bluepin, output);
}
 
void loop() {
    int delayvalue = serial.parseint();
  while (serial.available() > 0) {
    if (serial.read() == '\n') {
         
      red1 = random(0, 255);
      green1 = random(0, 255);
      blue1 = random(0, 255);
     
      analogwrite(redpin, red1);
      analogwrite(greenpin, green1);
      analogwrite(bluepin, blue1);
      delay(delayvalue);
    }
}
}

i don't think code likes delay(0);  has been a discussion topic before. try making @ least 1, or comment out.

add serial print of delayvalue after line, see you're getting.
code: [select]

void loop() {
    int delayvalue = serial.parseint();


Arduino Forum > Using Arduino > Programming Questions > Led Random Color Delay Value Problem


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'