Test program for RotaryEncoder class.

Dependencies:   RotaryEncoder

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

Committer:
ryood
Date:
Sat Sep 22 23:48:23 2018 +0000
Revision:
78:81fefe1bbf2d
Parent:
77:340f583d7769
Clean up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jonathan Austin 0:2757d7abb7d9 1 #include "mbed.h"
ryood 77:340f583d7769 2 #include "RotaryEncoder.h"
Jonathan Austin 0:2757d7abb7d9 3
ryood 77:340f583d7769 4 Serial pc(USBTX, USBRX); // tx, rx
Jonathan Austin 0:2757d7abb7d9 5 DigitalOut led1(LED1);
Jonathan Austin 0:2757d7abb7d9 6
ryood 77:340f583d7769 7 //RotaryEncoder(PinName pin1_name, PinName pin2_name, int min = 0, int max = 100, int val = 50);
ryood 77:340f583d7769 8 RotaryEncoder re1(D2, D3, 0, 8, 4);
ryood 77:340f583d7769 9 RotaryEncoder re2(D4, D5, -8, 0, -4);
ryood 77:340f583d7769 10
Jonathan Austin 1:846c97078558 11 // main() runs in its own thread in the OS
Jonathan Austin 0:2757d7abb7d9 12 int main() {
ryood 77:340f583d7769 13 pc.printf("Rotary Encoder Test\r\n");
ryood 77:340f583d7769 14
ryood 77:340f583d7769 15 re1.setInterval(2000);
ryood 77:340f583d7769 16 re2.setInterval(2000);
ryood 77:340f583d7769 17
ryood 77:340f583d7769 18 pc.printf("re1: min=%d max=%d interval=%d\r\n", re1.getMin(), re1.getMax(), re1.getInterval());
ryood 77:340f583d7769 19 pc.printf("re2: min=%d max=%d interval=%d\r\n", re2.getMin(), re2.getMax(), re2.getInterval());
ryood 77:340f583d7769 20
Jonathan Austin 0:2757d7abb7d9 21 while (true) {
ryood 77:340f583d7769 22 pc.printf("%d\t%d\r\n", re1.getVal(), re2.getVal());
Jonathan Austin 0:2757d7abb7d9 23 led1 = !led1;
ryood 77:340f583d7769 24 wait(0.1);
Jonathan Austin 0:2757d7abb7d9 25 }
Jonathan Austin 0:2757d7abb7d9 26 }
Jonathan Austin 1:846c97078558 27