极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10890|回复: 4

求助 中断函数

[复制链接]
发表于 2014-10-15 22:06:17 | 显示全部楼层 |阅读模式
在网上看了写中断函数的例子,对attachInterrupt(0, 函数, LOW);语句中间的“函数”一直不会用,比如我想在下面写一个中断的for函数,这里attachInterrupt语句里的“函数”我需要写什么?程序的最开始需要申明这个函数吗?如何申明?这语句中的函数一般都是什么函数?
回复

使用道具 举报

 楼主| 发表于 2014-10-15 22:07:00 | 显示全部楼层
还有一个问题:我在 官网上摘抄一段 中断函数都会报错……是不是板子问题?
attachInterrupt(0, blink, change);
提示是blink was not declared in this scope
求高手解答
回复 支持 反对

使用道具 举报

发表于 2014-10-16 09:19:42 | 显示全部楼层
  1. int pin = 13;
  2. volatile int state = LOW;

  3. void setup()
  4. {
  5.   pinMode(pin, OUTPUT);
  6.   attachInterrupt(0, blink, CHANGE);
  7. }

  8. void loop()
  9. {
  10.   digitalWrite(pin, state);
  11. }

  12. void blink()
  13. {
  14.   //中断函数中写你想做的操作,中断函数中的程序越简单越好。
  15.   state = !state;
  16. }
复制代码
更多关于中断的用法,参考这里:
http://arduino.cc/en/Reference/AttachInterrupt
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-10-16 21:02:06 | 显示全部楼层
谢谢先,不过我是复制的您那段程序啊,还是报错呢……就是提示是blink was not declared in this scope。
一直搞不懂是哪里出的问题~我的板子是买的淘宝教学套件,是不是少了什么程序才这样子?
回复 支持 反对

使用道具 举报

发表于 2014-10-16 22:18:21 | 显示全部楼层
hustwhzl 发表于 2014-10-16 21:02
谢谢先,不过我是复制的您那段程序啊,还是报错呢……就是提示是blink was not declared in this scope。
...
  1. int pin = 13;
  2. volatile int state = LOW;

  3. void blink()
  4. {
  5.   //中断函数中写你想做的操作,中断函数中的程序越简单越好。
  6.   state = !state;
  7. }

  8. void setup()
  9. {
  10.   pinMode(pin, OUTPUT);
  11.   attachInterrupt(0, blink, CHANGE);
  12. }

  13. void loop()
  14. {
  15.   digitalWrite(pin, state);
  16. }

复制代码


你的IDE的版本?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-9 00:46 , Processed in 0.037490 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表