Ryo Od / Mbed OS RotaryEncoder_Test

Dependencies:   RotaryEncoder

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "RotaryEncoder.h"
00003 
00004 Serial pc(USBTX, USBRX); // tx, rx
00005 DigitalOut led1(LED1);
00006 
00007 //RotaryEncoder(PinName pin1_name, PinName pin2_name, int min = 0, int max = 100, int val = 50);
00008 RotaryEncoder re1(D2, D3, 0, 8, 4);
00009 RotaryEncoder re2(D4, D5, -8, 0, -4);
00010 
00011 // main() runs in its own thread in the OS
00012 int main() {
00013     pc.printf("Rotary Encoder Test\r\n");
00014     
00015     re1.setInterval(2000);
00016     re2.setInterval(2000);
00017     
00018     pc.printf("re1: min=%d max=%d interval=%d\r\n", re1.getMin(), re1.getMax(), re1.getInterval());
00019     pc.printf("re2: min=%d max=%d interval=%d\r\n", re2.getMin(), re2.getMax(), re2.getInterval());
00020 
00021     while (true) {
00022         pc.printf("%d\t%d\r\n", re1.getVal(), re2.getVal());
00023         led1 = !led1;
00024         wait(0.1);
00025     }
00026 }
00027