Arduino 基本设置 + timer

来源:互联网 发布:e站app 显示网络错误 编辑:程序博客网 时间:2024/05/19 17:50

这次的文章目的是从一个Arduino的0基础新人的角度进行timer的编程下载和调试。
感谢Beck的教学~ 第一次感觉arduino还是挺亲切的233
timer library 文件:http://download.csdn.net/detail/u013429988/9836229
或者从github上下载:http://github.com/JChristensen/Timer

1. Arduino IDE 界面:



2.如何下载烧录程序:
(1). 首先要选择和自己的arduino板子一致的

这里写图片描述

(2). 然后要选择下载用的串口,你可以在tool->port中看到arduino 的IDE 中自动检测到的port 和板子


这里写图片描述

(3)编译,下载,运行。
烧录的时候右下角会有小进度条 (compiling,uploading):
这里写图片描述

如何确定程序已经下载完毕,并且已经在运行:
这里写图片描述

3. 如何给sketch添加公用的library
在安装完 arduino的IDE之后就会在文档中自动生成一个Arduino的文件夹。
把library文件放在这个文件夹下,就让所有的sketch都自动调用这些library文件了。
这里写图片描述

4. Timer 调用一个完整的Timer 库
在添加好库文件之后,就可以在代码中使用库文件了。
这里写图片描述

5. 如何监控运行中的变量


这里写图片描述

在烧录完成之后运行时怎样才能看到打印出来的变量呢?
点击右上角的放大镜标志,如下图所示:


这里写图片描述

会跳出来一个窗口,里面就是print的数据:
这里写图片描述

经测试,基本就是一秒加一,没有什么问题。

代码:

//Flash two LEDs at different rates using Simon Monk's Timer library//http://www.doctormonk.com/2012/01/arduino-timer-library.html////Jack Christensen 30Sep2013////Beerware license: Free for any and all purposes, but if you find it//useful AND we actually meet someday, you can buy me a beer!#include "Timer.h"                     //http://github.com/JChristensen/Timerconst int LED1 = 8;                    //connect one LED to this pin (with appropriate current-limiting resistor of course)const int LED2 = 9;                    //connect another LED to this pin (don't forget the resistor)const unsigned long PERIOD1 = 1000;    //one secondconst unsigned long PERIOD2 = 10000;   //ten secondsTimer t;                               //instantiate the timer objectint i=0;void setup(void){    Serial.begin(9600);    pinMode(LED1, OUTPUT);    pinMode(LED2, OUTPUT);    t.oscillate(LED1, PERIOD1, HIGH);    t.oscillate(LED2, PERIOD2, HIGH);    t.every(1000,callbackfun);//unit:ms,self-writen function.}void loop(void){    t.update();}void callbackfun(void){if(i>100)    {      i=0;      }      else      {        i=i+1;        }    Serial.println(i);  }

完结★,°:.☆( ̄▽ ̄)/$:.°★

0 0
原创粉丝点击