LoginSignup
0
0

More than 5 years have passed since last update.

arduinoでパルスジェネレータ

Posted at

概要

arduino nanoでパルスジェネレータをやってみた。

写真

MVC-021S.JPG

ログ

pulse.JPG

サンプルコード

#include <MsTimer2.h>

void timer2()
{
    digitalWrite(13, HIGH);
    delay(1);
    digitalWrite(13, LOW);
}
void setrev(int rpm)
{
    unsigned long ms = 60000 / rpm;
    MsTimer2::set(ms, timer2);
    MsTimer2::start();
}
void setup()
{
    pinMode(13, OUTPUT);
    Serial.begin(115200);
    digitalWrite(13, HIGH);
    setrev(1000);
    Serial.println("setrev 1000rpm");
}
void loop()
{
    String line = Serial.readStringUntil('\n');
    int rpm = line.toInt();
    if (line != "")
    {
        if (rpm == 0)
        {
            Serial.println("error");
        }
        else
        {
            Serial.print("rpm : ");
            Serial.println(rpm);
            setrev(rpm);
        }
    }
}
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