Vincent Ceyssens
/
4180_final_encoder
This is the encoder code
Diff: main.cpp
- Revision:
- 0:ddf6b258e38a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Apr 30 23:48:27 2017 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" + +DigitalOut myled(LED1); +InterruptIn encoder(p15); +Serial pc(USBTX, USBRX); +int ticker; + +void ticker_func() +{ + ticker++; + +} +int main() { + + encoder.mode(PullUp); + encoder.fall(&ticker_func); + encoder.rise(&ticker_func); + double distance = 0; + + while(1) { + myled=encoder; + distance = double(ticker)*2.5/12; + pc.printf("\r\n distance covered '%i'", ticker); + wait(1); + + } +}