Noduino Interrupts
来自Jack's Lab
(版本间的差异)
(以“== Overview == <br><br>”为内容创建页面) |
(→Examples) |
||
| (未显示1个用户的6个中间版本) | |||
| 第1行: | 第1行: | ||
== Overview == | == Overview == | ||
| + | |||
| + | * attachInterrupt() | ||
| + | * detachInterrupt() | ||
| + | |||
| + | |||
| + | * noInterrupts() --- disable the interrupt | ||
| + | * Interrupts() --- enable the interrupt | ||
| + | |||
| + | |||
| + | We suggest you to use: | ||
| + | |||
| + | * D8 (GPIO4), D9 (GPIO5) | ||
| + | * D4 (GPIO13), D5 (GPIO12), D6 (GPIO14) | ||
| + | * D2 (GPIO2) | ||
| + | <br><br> | ||
| + | |||
| + | == Examples == | ||
| + | |||
| + | [[文件:RotaryEncoderWaveform.gif]] | ||
| + | |||
| + | Use an encoder example: | ||
| + | |||
| + | * D8 connect to the channel A to receive the interrupt (rising) | ||
| + | * D9 connect to the channel B | ||
| + | |||
| + | <source lang=cpp> | ||
| + | #include "noduino.h" | ||
| + | |||
| + | static int32_t pos = 0; | ||
| + | static bool past_b = 0; | ||
| + | |||
| + | void do_encoder_a() | ||
| + | { | ||
| + | past_b = (bool)digitalRead(D9); | ||
| + | past_b ? pos++ : pos--; | ||
| + | serial_printf("pos = %d\r\n", pos); | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | serial_begin(115200); | ||
| + | |||
| + | pinMode(D9, INPUT); | ||
| + | |||
| + | attachInterrupt(D8, do_encoder_a, RISING); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | } | ||
| + | </source> | ||
| + | |||
| + | |||
| + | You can try the example in noduino-sdk/examples/noduino/encoder | ||
| + | |||
| + | <br><br> | ||
| + | |||
| + | == Reference == | ||
| + | |||
| + | * [[Noduino]] | ||
| + | |||
| + | |||
| + | <br><br> | ||
| + | <br><br> | ||
| + | <br><br> | ||
| + | <br><br> | ||
| + | <br><br> | ||
| + | <br><br> | ||
| + | <br><br> | ||
| + | <br><br> | ||
<br><br> | <br><br> | ||
2016年9月5日 (一) 12:35的最后版本
[编辑] 1 Overview
- attachInterrupt()
- detachInterrupt()
- noInterrupts() --- disable the interrupt
- Interrupts() --- enable the interrupt
We suggest you to use:
- D8 (GPIO4), D9 (GPIO5)
- D4 (GPIO13), D5 (GPIO12), D6 (GPIO14)
- D2 (GPIO2)
[编辑] 2 Examples
Use an encoder example:
- D8 connect to the channel A to receive the interrupt (rising)
- D9 connect to the channel B
#include "noduino.h"
static int32_t pos = 0;
static bool past_b = 0;
void do_encoder_a()
{
past_b = (bool)digitalRead(D9);
past_b ? pos++ : pos--;
serial_printf("pos = %d\r\n", pos);
}
void setup()
{
serial_begin(115200);
pinMode(D9, INPUT);
attachInterrupt(D8, do_encoder_a, RISING);
}
void loop()
{
}
You can try the example in noduino-sdk/examples/noduino/encoder
[编辑] 3 Reference
