Generation of three phase square wave using arduino(SIMPLE CODING)

The following simple code generates 3 phase square wave using arduino UNO. and no other components required. :slight_smile:
ENJOY!!

void setup() {
// initialize digital pin 13,12&8 as an output.
pinMode(13, OUTPUT);
pinMode(12,OUTPUT);
pinMode(8,OUTPUT);

}

void loop() {
int var=0;
digitalWrite(13, HIGH);
digitalWrite(8,LOW);
digitalWrite(12,LOW);
delay(6.67);
digitalWrite(12,HIGH);
while(var==0){
delay(3.33);
digitalWrite(13,LOW);
delay(3.33);
digitalWrite(8,HIGH);
delay(3.34);
digitalWrite(12,LOW);
delay(3.33);
digitalWrite(13,HIGH);
delay(3.33);
digitalWrite(8,LOW);
delay(3.34);
digitalWrite(12,HIGH);
}
}

_50Hz.ino (537 Bytes)

I think you need to read the documentation and figure out how delay(3.34) is no different from delay(3.33).

As well as which programs that use the delay() function are little use for anything other than a simple demo.

And please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

...R

1 Like

But it's gautam_gyanu1's first post, I'm sure he's proud of it.
Maybe move it to Programming and change the delay(3.33) to delayMicroseconds (3330) and (3340) and (6670) or the closest multiple of 4uS.
Course, blink without delay style would be better to allow other stuff to happen during the wait times.

1 Like