hi guys know there must easier way new code.
below code pwm using bit-banging pulse width modulation. reason went route because need add pulse @ end of each loop. there way run both loops simultaneously when run seem run 1 output signal @ time.
below code pwm using bit-banging pulse width modulation. reason went route because need add pulse @ end of each loop. there way run both loops simultaneously when run seem run 1 output signal @ time.
code: [select]
void setup()
{
pinmode(13, output);
pinmode(12, output);
}
void loop() {
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(1269);
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(519); // pulse
digitalwrite(13, high);
delaymicroseconds(231);
digitalwrite(13, low);
delaymicroseconds(519);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(8769);
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(4269); // pulse
digitalwrite(12, high);
delaymicroseconds(231);
digitalwrite(12, low);
delaymicroseconds(4269);
}
look in ide @ example sketches loops , arrays sketches , learn that. blink without delay , learn that. @ point can shorten , merge variably blinking leds.
perhaps won't need array if counter , formula can generate pulse widths.
perhaps won't need array if counter , formula can generate pulse widths.
Arduino Forum > Using Arduino > Programming Questions > Simultaneous loops using PWM Bit-Bang
arduino
Comments
Post a Comment