Setting two frequencies for Arquino Uno

Hi
I am a beginner of using Arduino Uno.
I would like to set up two frequencies as drawn in the picture attached.

I would like to set 100 Hz with 1 ms pulse. so the delay between high and low is 1ms and low and next high is 9ms. when this 100Hz reaches 5 times, I want to set a “low” of 2450 ms. This is one cycle. I want to have 24 cycles.

Could anyone help advise where is wrong?

Thanks in advance!

int laser = 13 ; ;
int count;
int countNum = 0;

void setup() {
// put your setup code here, to run once:
pinMode(laser, OUTPUT);

Serial.begin(9600);

}

void loop() {
// put your main code here, to run repeatedly:
for(count=0; count<6; count = count+1)
{

digitalWrite(laser, HIGH);
delay(1);
digitalWrite(laser, LOW);
delay(9);
countNum=count+1;
if (countNum == 5){
digitalWrite(laser, LOW);
delay(2450);}

}
while(24){}
}

while(24){}

This is an infinite loop that does nothing. Is that intentional ?

for(count=0; count<6; count = count+1)

This for loop will execute 6 times with count values 0, 1, 2 ,3, 4 and 5
Is that what you want ?

A for loop than counts 0 to 23 inclusive,
{
a for loop that counts 0 to 4 inclusive
{
Laser on
Delay one millisecond
Laser off
Delay 9 milliseconds
}
Delay 2450 milliseconds
}

Hi TheMemberFormerlyKnownAsAWOL,

I modified the script but error appeared. Sorry I guess I might misunderstand your suggestion.
Could you suggest? thank you!

int laser = 13 ; ;
int count;
int countNum = 0;
int count1;
int countNum1 = 0;

void setup() {
// put your setup code here, to run once:
pinMode(laser, OUTPUT);

Serial.begin(9600);

}

void loop()
{

for(count1=0; count1<24; count1 = count1+1)
void loop ()
{
for(count=0; count<5; count = count+1)
{
digitalWrite(laser, HIGH);
delay(1);
digitalWrite(laser, LOW);
delay(9);
countNum=count+1;

}
}
digitalWrite(laser, LOW);
delay(2450);
countNum1=count1+1;
}

…and?

I don’t know what the countNum variables are for.

}
    digitalWrite(laser, LOW);
    delay(2450);

At this point, the laser pin is already LOW.
Unless you’re practising defensive programming, the digitalWrite is pointless.

You can’t have a function definition inside another function - the compiler already told you that when you compiled it, though maybe not in those words.

The loop control variables do not need global scope.

Please remember to use code tags when posting code

May I know how to add nested loop? In your previous reply, there are two 'for loop' suggested. Could you provide an example ? Thanks.

for (int y = 0; y < yLimit; y++){
  for ( int x = 0; x < xLimit; x++) {
      // Some code here
  }
  // Maybe some more code here
}

if you don’t like nested for, you can call a function too

const int laser = 13 ;                                                         

void setup() 
{
    // put your setup code here, to run once:
  pinMode(laser, OUTPUT);

  Serial.begin(9600);
}

// function that does five 10 ms cycles plus 2450 ms pause
void oneLaserCyclePlease()
{
  // here does five cycles 
  for (int i=0; i<5; i++)
    { 
      digitalWrite(laser, HIGH);
      delay(1);
      digitalWrite(laser, LOW);
      delay(9);
    }
    
    // after five cycles, does the 2450 ms pause
    // laser is already LOW here, no need for
    //  digitalWrite(laser, LOW);    
    delay(2450);                  
}

void loop() 
{
  // put your main code here, to run repeatedly:
  
  // here does 24 cycles
  for(int count=0; count<24; count++)  
    // every cycle calls this function 
    oneLaserCyclePlease();

    // what you want to do now? you know    
}

Aye:
Hi
I am a beginner of using Arduino Uno.
I would like to set up two frequencies as drawn in the picture attached.

I would like to set 100 Hz with 1 ms pulse. so the delay between high and low is 1ms and low and next high is 9ms. when this 100Hz reaches 5 times, I want to set a “low” of 2450 ms. This is one cycle. I want to have 24 cycles.

Could anyone help advise where is wrong?

Thanks in advance!

It should look more like this:

const byte LaserPin = 13 ;                                                         ;

void setup()
{
  digitalWrite(LaserPin, LOW);
  pinMode(LaserPin, OUTPUT);

  for (int cycles = 0; cycles < 245; cycles++)
  {
    // 5 pulses, 1 ms ON, 9 ms OFF
    for (int pulses = 0; pulses < 5; pulses++)
    {
      digitalWrite(LaserPin, HIGH);
      delay(1);
      digitalWrite(LaserPin, LOW);
      delay(9);
    } // end of 'for (int pulses;'
    // And then stay low for another 2450 ms
    delay(2450);
  } // end of 'for (int cycles;'
}

void loop() {}