Arduinoでライブラリを使わずPWM

2018/04/09 23:58arduino
unsigned long ts;
void setup() {
    ts = micros();
    DDRB = DDRB | B11111111;
}

void loop() {
    unsigned long t = micros() - ts;

    if(t <= 1500) {
        PORTB = PORTB | B00100000;
    }
    else {
        PORTB = B00000000;
    }

    if(t >= 20000) {
        ts = micros();
    }
}