zoukankan      html  css  js  c++  java
  • arduino 驱动电调

    #include <TimerOne.h>
    
    #define PPMPIN 7
    
    byte ppm=1; //0-9
    byte count=0;
    void setup() {
      // put your setup code here, to run once:
     pinMode(PPMPIN,OUTPUT);
     Serial.begin(9600);
     Timer1.initialize(100);// 设置定时器中断时间,单位微秒,此处为1秒
     Timer1.attachInterrupt( timerIsr ); // 打开定时器中断
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      while(Serial.available()){
         char c= Serial.read();
         if(c>='0' && c<='9'){
           ppm=((byte)c) - 38;
          Serial.println(ppm);
         }
      }
    }
    
    //定时器中断处理函数
    void timerIsr()
    {
      
      if(count>200)count=0;
      
      if(count<=ppm){
        digitalWrite(PPMPIN,HIGH);
      }else{
        digitalWrite(PPMPIN,LOW);
       }
       count++;
    }
    View Code

    采用TimeOne组件,这个通过T/C定时触发中断处理, 设置100微秒,每次中断累加1,直到200,这样产生的50HZ的PWM,控制比较参数ppm可以调节脉款

    电调低油门是0.7ms高油门是1.7ms

    可以设置ppm1,ppm2,ppm3等多个输出,

  • 相关阅读:
    gems gems gems
    poj 6206 Apple
    lightoj1341唯一分解定理
    lightoj1370欧拉函数
    约瑟夫环lightoj1179
    拓展欧几里得算法
    RMQ算法
    poj1502MPI Maelstrom
    poj1860Currency Exchange
    生成全排列
  • 原文地址:https://www.cnblogs.com/wdfrog/p/5229631.html
Copyright © 2011-2022 走看看