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 "DebouncedIn.h" 00003 #include "TextLCD.h" 00004 00005 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00006 int i,Sp=0,Kp,Ki,Kd; 00007 DigitalOut l1(LED1); 00008 DigitalOut l2(LED2); 00009 int main() 00010 { 00011 DebouncedIn button1(PTC12); 00012 DebouncedIn button2(PTC13); 00013 DebouncedIn button3(PTC16); 00014 lcd.writeCommand(0x0E); 00015 lcd.printf("Sp= Kp="); 00016 lcd.locate(0,1); 00017 lcd.printf("Ki= Kd="); 00018 lcd.locate(2,0); 00019 lcd.printf("="); 00020 00021 while(1) { 00022 00023 if(button1.falling()) { 00024 00025 switch(i) { 00026 case 0: 00027 lcd.locate(2,0); 00028 lcd.printf("= "); 00029 lcd.locate(3,0); 00030 lcd.printf("%d",++Sp); 00031 00032 break; 00033 case 1: 00034 lcd.locate(10,0); 00035 lcd.printf("= "); 00036 lcd.locate(11,0); 00037 lcd.printf("%d",++Kp); 00038 break; 00039 case 2: 00040 00041 lcd.locate(2,1); 00042 lcd.printf("= "); 00043 lcd.locate(3,1); 00044 lcd.printf("%d",++Ki); 00045 break; 00046 case 3: 00047 lcd.locate(10,1); 00048 lcd.printf("= "); 00049 lcd.locate(11,1); 00050 lcd.printf("%d",++Kd); 00051 break; 00052 } 00053 } 00054 if(button2.falling()) { 00055 switch(i) { 00056 case 0: 00057 if(Sp<0) { 00058 Sp=0; 00059 } 00060 lcd.locate(2,0); 00061 lcd.printf("= "); 00062 lcd.locate(3,0); 00063 lcd.printf("%d",Sp--); 00064 break; 00065 case 1: 00066 if(Kp<0) { 00067 Kp=0; 00068 } 00069 lcd.locate(10,0); 00070 lcd.printf("= "); 00071 lcd.locate(11,0); 00072 lcd.printf("%d",Kp--); 00073 break; 00074 case 2: 00075 00076 if(Ki<0) { 00077 Ki=0; 00078 } 00079 lcd.locate(2,1); 00080 lcd.printf("= "); 00081 lcd.locate(3,1); 00082 lcd.printf("%d",Ki--); 00083 break; 00084 case 3: 00085 00086 if(Kd<0) { 00087 Kd=0; 00088 } 00089 lcd.locate(10,1); 00090 lcd.printf("= "); 00091 lcd.locate(11,1); 00092 lcd.printf("%d",Kd--); 00093 break; 00094 } 00095 } 00096 if(button3.falling()) { 00097 i++; 00098 if(i>3) { 00099 i=0; 00100 } 00101 switch (i) { 00102 case 0: 00103 lcd.locate(2,0); 00104 lcd.printf("="); 00105 break; 00106 case 1: 00107 lcd.locate(10,0); 00108 lcd.printf("="); 00109 break; 00110 case 2: 00111 lcd.locate(2,1); 00112 lcd.printf("="); 00113 break; 00114 case 3: 00115 lcd.locate(10,1); 00116 lcd.printf("="); 00117 break; 00118 } 00119 } 00120 } 00121 }
Generated on Sun Jul 31 2022 13:42:38 by
1.7.2