Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "QEI.h" 00003 #define ROTATE_PER_REVOLUTIONS 48 00004 DigitalOut led1(LED1); 00005 DigitalOut led2(LED2); 00006 DigitalOut led3(LED3); 00007 DigitalOut led4(LED4); 00008 Ticker timer1; 00009 Ticker timer2; 00010 Serial pc(USBTX, USBRX); // tx, rx pc hyper terminal 00011 QEI wheel1(D1,D0,NC, ROTATE_PER_REVOLUTIONS, QEI::X4_ENCODING); 00012 int buf,cfd,predata,pulse1,pulse2; 00013 00014 void disp() { 00015 /*lcd.locate(0,0); 00016 lcd.printf("ec1:%03d ec2:%03d\n", pulse1,pulse2); 00017 lcd.locate(0,1); 00018 lcd.printf("cfd:%03d\n", cfd); */ 00019 printf("encoder1: %02d\n\r", pulse1); 00020 printf("encoder2: %02d\n\r", pulse2); 00021 printf("cfd:%03d\n\r", cfd); 00022 led2=!led2; //check 00023 } 00024 void encoder() { 00025 pulse1 = wheel1.getPulses()/4; 00026 //pulse2 = wheel2.getPulses()/4; 00027 led4=!led4; //check 00028 } 00029 int main() 00030 { 00031 timer1.attach_us(&disp, 50000); //100ms 00032 timer2.attach_us(&encoder,10); //10ms 00033 printf("Opt Feder X1"); 00034 while(1) 00035 { 00036 led3=!led3;//check 00037 if(pc.readable()) { 00038 buf = pc.getc(); 00039 if(buf == 127) 00040 { //to aboid freeze issue at 127 not fixed. 00041 buf =pc.getc(); 00042 } 00043 cfd = buf; 00044 if(buf != predata) 00045 { 00046 if(buf >= 3) 00047 { 00048 led1 = 1; 00049 } 00050 else{ 00051 led1 =0; 00052 } 00053 //cfd = buf; 00054 predata = buf; 00055 00056 }//if(x1 != predata) 00057 00058 }//if(device.readable()) 00059 } 00060 }
Generated on Tue Jul 19 2022 07:33:39 by
1.7.2