Robocon_IPS / Mbed 2 deprecated Encoder

Dependencies:   QEI TextLCD mbed

Fork of LCD by Robocon_IPS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "QEI.h"
00004 
00005 // BUTTON
00006 InterruptIn button(USER_BUTTON);
00007 
00008 // for debugging
00009 //Serial pc(USBTX, USBRX, 115200);
00010 
00011 // ENCODER
00012 #define N 1000
00013 QEI wheel(PA_5, PA_6, PA_7, N, QEI::X4_ENCODING); // A, B, Z, pulses/revolution, mode
00014 
00015 // 2x16 LCD
00016 TextLCD lcd(PC_11,PC_10,PC_0,PC_3,PC_1,PC_2); // RS, E, D4-D7
00017 
00018 void pressed() {
00019     lcd.printf("Button Pressed\n");
00020     wheel.reset();
00021 }
00022 
00023 int main()
00024 {
00025     //pc.format(8,SerialBase::None,1);
00026     button.fall(&pressed);
00027     lcd.cls();
00028     lcd.locate(0,0);
00029     lcd.printf("Wellcome!");
00030     int p,r;
00031     while(1) {
00032         p = wheel.getPulses();
00033         r = wheel.getRevolutions();
00034         lcd.locate(0,1);
00035         lcd.printf("p : %i, r : %i\n",p,r);
00036         //pc.printf("p : %i, r : %i\n",p,r);
00037         wait(0.1);
00038         lcd.cls();
00039     }
00040 }