
I want to make a sequential PWM through Arduino UNO.
Please refer to the image.
- I want to turn on/off the LED through the control of 4 digital pins.
- ON-TIME time of 4 digital pins is 100us.
- It should turn on and off sequentially.
- It can be created through 'digitalWrite()', but the exact value does not come out.
- By any chance, there is no other way.
- The digital output can be any pin on the Arduino Uno.
#define pwm_p1 2
#define pwm_p2 3
#define pwm_p3 4
#define pwm_p4 5
long TIMER_EVENT = 0;
void setup(){
Serial.begin(115200);
pinMode(pwm_p1,OUTPUT); pinMode(pwm_p2,OUTPUT);
pinMode(pwm_p3,OUTPUT); pinMode(pwm_p4,OUTPUT);
}
void loop(){
if(TIMER_EVENT < millis()){
TIMER_EVENT = millis() + 1;
digitalWrite(pwm_p1, HIGH);
delayMicroseconds(100);
digitalWrite(pwm_p1, LOW);
delayMicroseconds(100);
digitalWrite(pwm_p2, HIGH);
delayMicroseconds(100);
digitalWrite(pwm_p2, LOW);
delayMicroseconds(100);
digitalWrite(pwm_p3, HIGH);
delayMicroseconds(100);
digitalWrite(pwm_p3, LOW);
delayMicroseconds(100);
digitalWrite(pwm_p4, HIGH);
delayMicroseconds(100);
digitalWrite(pwm_p4, LOW);
delayMicroseconds(100);
}
}