How do i combine two codes of arduino?

first code
float rpm=0;

void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(sensor,INPUT_PULLUP);
lcd.setCursor(0,0);
lcd.print(" STEPS - 0");
lcd.setCursor(0,1);
lcd.print(" RPM - 0.00");
}

void loop()
{
start_time=millis();
end_time=start_time+1000;
while(millis()<end_time)
{
if(digitalRead(sensor))
{
steps=steps+1;
while(digitalRead(sensor));
}
lcd.setCursor(9,0);
lcd.print(steps);
lcd.print(" “);
}
temp=steps-steps_old;
steps_old=steps;
rpm=(temp*60);
lcd.setCursor(9,1);
lcd.print(rpm);
lcd.print(” ");
}

This program will display the speed of motor

second code

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

}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, LOW);
delayMicroseconds(0); // approximately 50% duty cycle @ 50HZ
digitalWrite(13, HIGH);
delayMicroseconds(10000 - 0);

}

This program will control firing angle for triac

I have tested both programs individually and it worked.
I was wondering if if i can combine both programs together.

Can someone please help? :slight_smile:
Thank you!! Appreciate much!! :slight_smile:

The first code doesn’t even compile,

Please remember to use code tags

In your first code you have

while(millis()<end_time)
 {
   if(digitalRead(sensor))
   {
    steps=steps+1;
    while(digitalRead(sensor));
   }
   lcd.setCursor(9,0);
   lcd.print(steps);
   lcd.print("   ");
 }

This stops the program from doing anything else for at least 1 second. Is it OK for the second program to do nothing for the same period ?

no
is there any method to combined these two code ?

I try for mix them but the program 2 not working will

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int sensor = 11;
unsigned long start_time = 0;
unsigned long end_time = 0;
int steps=0;
float steps_old=0;
float temp=0;
float rpm=0;

void setup()
{
pinMode(8, OUTPUT); //FOR PULSE

Serial.begin(9600);
lcd.begin(16, 2);
pinMode(sensor,INPUT_PULLUP);
lcd.setCursor(0,0);
lcd.print(" STEPS - 0");
lcd.setCursor(0,1);
lcd.print(" RPM - 0.00");
}

void loop()
{
// FOR PULSE
digitalWrite(8, LOW);
delayMicroseconds(5000); // approximately 50% duty cycle @ 50HZ
digitalWrite(8, HIGH);
delayMicroseconds(10000 - 5000);

start_time=millis();
end_time=start_time+1000;
while(millis()<end_time)
{
if(digitalRead(sensor))
{
steps=steps+1;
while(digitalRead(sensor));
}
lcd.setCursor(9,0);
lcd.print(steps);
lcd.print(" “);
}
temp=steps-steps_old;
steps_old=steps;
rpm=(temp*60);
lcd.setCursor(9,1);
lcd.print(rpm);
lcd.print(” ");
}

these will give me full wave
does not give me what I want

when I used suppurated I get correct wave

Do not cross-post

Second topic deleted