LoginSignup
0
0

More than 5 years have passed since last update.

wemosでtimer その2

Posted at

概要

wemosでtimerやってみた。
timer0やってみた。良くない。

環境

  • wemos d1 r1
  • arduino esp8266 v2.5.0-beta2

写真

12.png

サンプルコード

volatile unsigned long timeSpent = 1;
unsigned long prevm = 0;
void isrt0(void)
{
    timer0_write(ESP.getCycleCount() + 10000L);
    unsigned long now;
    int state = digitalRead(LED_BUILTIN);
    digitalWrite(LED_BUILTIN, !state);
    now = micros();
    timeSpent = now - prevm;
    prevm = now;
}
void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);
    Serial.begin(115200);
    noInterrupts();
    timer0_isr_init();
    timer0_attachInterrupt(isrt0);
    timer0_write(ESP.getCycleCount() + 10000L);
    interrupts();
}
void loop()
{
    Serial.println(timeSpent);
    delay(100);
}

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0