LoginSignup
0
0

More than 5 years have passed since last update.

wemosでtimer

Last updated at Posted at 2019-02-07

概要

wemosでtimerやってみた。
1khzしか、出ない。精度が悪すぎ。腐ってる。

環境

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

波形

001.png

シリアルプロット

gg.jpg

サンプルコード

tickerを使った。

#include <Ticker.h>

Ticker tk;
volatile unsigned long timeSpent = 1;
unsigned long prevm = 0;
void isrt0(void)
{
    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);
    tk.attach_ms(1.0, isrt0);
}
void loop()
{
    Serial.println(timeSpent);
}

os_timer使った。

extern "C"
{
    #include "user_interface.h"
    #include "osapi.h"
}

os_timer_t t0;
volatile unsigned long timeSpent = 1;
unsigned long prevm = 0;
void isrt0(void * z)
{
    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);
    os_timer_setfn(&t0, isrt0, NULL);
    os_timer_arm(&t0, 1, true);
}
void loop()
{
    Serial.println(timeSpent);
}

以上。

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