SOS using AnalogWrite

I'm not sure if this is where this should be posted or not. So forgive me if I'm wrong. I am trying to make a RGB LED strip blink SOS in Morse code. I've successfully made a single LED using DigitalWrite blink, however I am having a difficult time using AnalogWrite. The LED's work just not blinking SOS. Below is the code I am using:

//LED Red=256, Green=127, Blue=0
int Pin_LED_Red=3;
int Pin_LED_Green=5;
int Pin_LED_Blue=6;
void setup() {
  // set mode of pins as outputs to run once
  pinMode(Pin_LED_Red,OUTPUT);
  pinMode(Pin_LED_Green,OUTPUT);
  pinMode(Pin_LED_Blue,OUTPUT);


}

void loop() {
  // 3 Dits
  for(int x=0;x<3;x++)
  {
  analogWrite(Pin_LED_Red,250); // Mav intensity of red;
  analogWrite(Pin_LED_Green,125); // Half intensity of Green;
  analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
  delay(100); //DelaayON tine 100 ms
  
  // Off for 200 ms
  analogWrite(Pin_LED_Red,0);
  analogWrite(Pin_LED_Green,0);
  analogWrite(Pin_LED_Blue,0); 
  delay(200);
 // 3 Dahs
  for(int x=0;x<3;x++)
  analogWrite(Pin_LED_Red,250); // Mav intensity of red;
  analogWrite(Pin_LED_Green,125); // Half intensity of Green;
  analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
  delay(300); //DelaayON tine 300 ms

 // Off for 200 ms
  analogWrite(Pin_LED_Red,0);
  analogWrite(Pin_LED_Green,0);
  analogWrite(Pin_LED_Blue,0); 
  delay(300);
  
   // 3 Dits
  for(int x=0;x<3;x++)
  analogWrite(Pin_LED_Red,259); // Mav intensity of red;
  analogWrite(Pin_LED_Green,125); // Half intensity of Green;
  analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
  delay(100); //DelaayON tine 100 ms
  }
}

Thanks for any and all help

moderator: added code tags ==> # button above the smileys

Check your { and }

where?

Wherever they appear; how else are you going to check them?

I'm sorry I misinterpreted your suggestion, I was looking for an AND statement

for(int x=0;x<3;x++)
  analogWrite(Pin_LED_Red,250); // Mav intensity of red;
  analogWrite(Pin_LED_Green,125); // Half intensity of Green;
  analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange

And check where you don't have them, but where you should.

I though that if I hovered near one curly bracket, it would show its mate. It doesn't seem to do that

There aren't any (that was a clue) in the fragment I quoted.

Jasiu:
I though that if I hovered near one curly bracket, it would show its mate. It doesn't seem to do that

maybe you're not looking far enough away.

Jasiu:
I though that if I hovered near one curly bracket, it would show its mate. It doesn't seem to do that

Not hover; the cursor needs to be after the bracket you're seeking a mate for.

Or use auto format (tools menu) to show you the structure of your code. Auto formatting before posting saves every one time!

Mark

Speaking of saving time, why are you using analogWrite() to blink an LED?

I don't think he is. He's using to get different colours.

Mark

You can simplify the code a bit by using functions. Also, note that some of your comments don't square up with your code. Misleading comments are worse than no comments. Your last call to the RED led passed in a value of 259...probably not what you want. Also, Morse has a pretty well-defined relationship for spacing, but here I've just used the dot-to-dash ratio. Finally, delay() is not a good choice for program delays. (See the Blink Without Delay example provided with the IDE.)

//LED Red=256, Green=127, Blue=0
#define DIT 100
#define DAH (DIT * 3)

int Pin_LED_Red=3;
int Pin_LED_Green=5;
int Pin_LED_Blue=6;

void setup() {
  // set mode of pins as outputs to run once
  pinMode(Pin_LED_Red,OUTPUT);
  pinMode(Pin_LED_Green,OUTPUT);
  pinMode(Pin_LED_Blue,OUTPUT);
}

void loop() {
  int x;

  for(x = 0; x < 3; x++)    // Three dits
  {
    sendChar(DIT);  
    pause(DIT);
  }
  delay(DIT + DAH);         // Inter-character spacing for Morse
  
  for(x = 0; x < 3; x++) {  // Three dahs
    sendChar(DAH);  
    pause(DIT);
  }
  delay(DIT + DAH);     

  for(x = 0; x < 3; x++)    // Three dits
  {
    sendChar(DIT);  
    pause(DIT);
  }
  delay(DAH * 5);              // Rest between messages.
}

void pause(long ms)
{
  analogWrite(Pin_LED_Red,0);
  analogWrite(Pin_LED_Green,0);
  analogWrite(Pin_LED_Blue,0); 
  delay(ms);
}

void sendChar(long ms)
{
  analogWrite(Pin_LED_Red,250); // Mav intensity of red;
  analogWrite(Pin_LED_Green,125); // Half intensity of Green;
  analogWrite(Pin_LED_Blue,0); //No Blue because Red and Green make Orange
  delay(ms); 
}

Thank you so much! That is a much better way of doing it :slight_smile: