Adding analog commands to an CCRGB in an FSM

Trying to figure out this line. I have an CC RGB that on the yellow state should be analog red, 255, and green, 125. Just not sure how to inject the code.

int red = 11;
int green = 10;
int blue = 9;
int redButton = 6;
int yellowButton = 5;
int greenButton = 3;
int redState;
int greenState;
int yellowState;
int state;
unsigned long startTime;

void setup()
{
  Serial.begin(9600);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(redButton, INPUT_PULLUP);
  pinMode(greenButton, INPUT_PULLUP);
  pinMode(yellowButton, INPUT_PULLUP);
  digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
}

void loop()
{
  int redButtonState = digitalRead(redButton);
  {
    if (redButtonState)
    {
      if (redButtonState != redState)
      {
        state=0;
        startTime = millis();
      }
    }
  }
  redState = redButtonState;// recording end of current state
  int greenButtonState = digitalRead(greenButton);
  {
    if (greenButtonState)
    {
      if (greenButtonState != greenState)
      {
        state=1;
        startTime = millis();
      }
    }
  }
  greenState = greenButtonState; //recording end of state
  int yellowButtonState = digitalRead(yellowButton);
  {
    if (yellowButtonState)
    {
      if (yellowButtonState != yellowState)
      {
        state=2;
        startTime = millis();
      }
    }
  }
  yellowState = yellowButtonState; // recording end of state
  if (state == 0)
  {
    redFunction();
  }
  else if (state == 1)
  {
    greenFunction();
  }
  else if (state == 2)
  {
    yellowFunction();
  }
}

void redFunction()
{
  Serial.println("Red Mode");
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
  if (millis() - startTime >=1000UL)
  {
    digitalWrite(red, !digitalRead(red));
    startTime = millis();
  }
}
void greenFunction()
{
  Serial.println("Green Mode");
  digitalWrite(red,LOW);
  digitalWrite(blue,LOW);
  if (millis() - startTime >=1000UL)
  {
    digitalWrite(green, !digitalRead(green));
    startTime = millis();
  }
}
void yellowFunction()
{
  Serial.println("Yellow Mode");
  analogWrite(red,255);
  analogWrite(green,125);
  if (millis() - startTime >=1000UL)
  //WHAT GOES IN HERE????
  // analogWrite command? digitalRead on an analog command???
}

What goes in here?
Given that you wrote the code, or did you? It is an odd question.

It is off code as well.
In the yellow state you need to turn the blue off, and then after the if you need to turn the red and green off.

Grumpy_Mike:
What goes in here?
Given that you wrote the code, or did you? It is an odd question.

It is off code as well.
In the yellow state you need to turn the blue off, and then after the if you need to turn the red and green off.

Yeah I wrote the code. Where I put the //What goes here is because I don't know how to write an analog passage that will set red at 255 and green at 125 and still continue the on for one second and off for one second.

In the previous states it was easy since I am only sending a digitalWrite command for one object instead of two.

In the previous states it was easy since I am only sending a digitalWrite command for one object instead of two.

I am puzzled now.
Why not have two commands here in place of the one you had?
What is stopping you?

Grumpy_Mike:

In the previous states it was easy since I am only sending a digitalWrite command for one object instead of two.

I am puzzled now.
Why not have two commands here in place of the one you had?
What is stopping you?

In previous states like blue or red I used this to turn the appropriate LED on and off

digitalWrite(red, !digitalRead(red));

what I don't know how to do is use that command to make my RGB go to yellow and flash using an analogWrite red value of 255 and an analogWrite green value of 125 inside of yellow function.

I've experimented trying to put a few lines of code together to get the desired effect but I get compilation errors, so its obviously me not knowing how to write what I want the program to do.

so its obviously me not knowing how to write what I want the program to do.

Or even explain it.

Are you trying to make the LED blink yellow? If so, how many times each time the function is called?

you want something like this untested block of code:

void yellowFunction()
{
  Serial.println("Yellow Mode");
  if (millis() - startTime < 1000UL)
  {
    analogWrite(red,255);
    analogWrite(green,125);
    analogWrite(blue,0);  // sorry, i forgot this one
  }
  else if (millis() - startTime < 2000UL)
  {
  analogWrite(red,0);
  analogWrite(green,0);
  analogWrite(blue,0);//here too
  }
  else
  startTime = millis();
  //WHAT GOES IN HERE????
  // well... a friendly thanks, of course!
}

edit added turning off the blue led

Awesome advice as usual Lowell, Thanks again! Sent some karma your way. i am getting an error on this part

 Serial.println("Yellow Mode");
  if (millis() - startTime < 1000UL)
    digitalWrite(blue,LOW);
  analogWrite(red,255);
  analogWrite(green,125);
}

else if (millis() - startTime < 2000UL)//<<<<<<<<<<error 117: unqualed-id before 'else'

{
  digitalWrite(red,LOW);
  digitalWrite(green,LOW);
  digitalWrite(blue,LOW);
}
else
  startTime = millis();

you missed a brace:

Serial.println("Yellow Mode");
  if (millis() - startTime < 1000UL)
    digitalWrite(blue,LOW);
  analogWrite(red,255);
  analogWrite(green,125);
}

try:

Serial.println("Yellow Mode");
  if (millis() - startTime < 1000UL)
  {
    digitalWrite(blue,LOW);
    analogWrite(red,255);
    analogWrite(green,125);
  }

Yep, that's because i'm an idiot.

mgttrottier:
Yep, that's because i'm an idiot.

no, its because you are a human (I hope :astonished:)