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.
Dependencies: TextLCD mbed Motordriver PS_PAD
Fork of _Tugas_Hybrid_LCD_RizqiCahyoY by
main.cpp
00001 00002 #include "mbed.h" 00003 #include "TextLCD.h" 00004 #include "PS_PAD.h" 00005 #include "Motor.h" 00006 #include "encoderKRAI.h" 00007 00008 #include <string> 00009 using namespace std; 00010 00011 Thread thread2(osPriorityNormal, OS_STACK_SIZE, NULL); 00012 Thread thread1(osPriorityNormal, OS_STACK_SIZE, NULL); 00013 Thread thread3(osPriorityNormal, OS_STACK_SIZE, NULL); 00014 00015 TextLCD lcd(PA_9, PC_3, PC_2, PA_8, PB_0, PC_15, TextLCD::LCD20x4); //rs,e,d4-d7 00016 encoderKRAI enc1 (PC_14, PC_13, 11, encoderKRAI::X4_ENCODING); 00017 encoderKRAI enc2 (PC_0, PC_1, 11, encoderKRAI::X4_ENCODING); 00018 encoderKRAI enc3 (PB_10, PB_3, 11, encoderKRAI::X4_ENCODING); 00019 PS_PAD ps2(PB_15,PB_14,PB_13, PC_4); //(mosi, miso, sck, ss) 00020 00021 Motor motor3(PB_7, PA_14, PA_15); //motor4 00022 Motor motor2(PA_11, PA_6, PA_5); //motor2 00023 //Motor motor1(PA_10, PB_5, PB_4); //motor_griper 00024 Motor motor1(PB_6, PA_7, PB_12); //motor 3 00025 string a; 00026 00027 void dataJoystick(); 00028 void lcdPrint(); 00029 void motorP(); 00030 00031 Serial pc(USBTX,USBRX); 00032 00033 int main() 00034 { 00035 pc.baud(115200); 00036 ps2.init(); 00037 thread1.start(dataJoystick); 00038 thread2.start(lcdPrint); 00039 thread3.start(motorP); 00040 while (1) 00041 { 00042 // baca input 00043 /* 00044 ps2.poll(); 00045 if(ps2.read(PS_PAD::PAD_X)==1) a = "silang"; 00046 else if(ps2.read(PS_PAD::PAD_CIRCLE)==1) a = "lingkaran"; 00047 else if(ps2.read(PS_PAD::PAD_TRIANGLE)==1) a = "segitiga"; 00048 else if(ps2.read(PS_PAD::PAD_SQUARE)==1) a = "kotak"; 00049 else a = "NULL"; 00050 */ 00051 /* 00052 //tampilkan LCD 00053 lcd.locate(0,0); 00054 lcd.printf("input joystik :"); 00055 lcd.locate(0,1); 00056 lcd.printf("%s",a); 00057 00058 wait_ms(10); 00059 lcd.cls(); 00060 */ 00061 } 00062 } 00063 00064 void dataJoystick(){ 00065 while(true){ 00066 ps2.poll(); 00067 if(ps2.read(PS_PAD::PAD_X)==1) a = "silang"; 00068 else if(ps2.read(PS_PAD::PAD_CIRCLE)==1) a = "lingkaran"; 00069 else if(ps2.read(PS_PAD::PAD_TRIANGLE)==1) a = "segitiga"; 00070 else if(ps2.read(PS_PAD::PAD_SQUARE)==1) a = "kotak"; 00071 else a = "NULL"; 00072 } 00073 } 00074 00075 void lcdPrint(){ 00076 while (true){ 00077 lcd.cls(); 00078 int pulse1 = enc1.getPulses(); 00079 int pulse2 = enc2.getPulses(); 00080 int pulse3 = enc3.getPulses(); 00081 lcd.locate(0,0); 00082 lcd.printf("input : %s", a); 00083 lcd.locate(0,1); 00084 lcd.printf("enc1 = %d", pulse1); 00085 lcd.locate(0,2); 00086 lcd.printf("enc2 = %d", pulse2); 00087 lcd.locate(0,3); 00088 lcd.printf("enc3 = %d", pulse3); 00089 Thread::wait(20); 00090 } 00091 } 00092 00093 void motorP() { 00094 while(true){ 00095 motor1.speed(0.5); 00096 motor2.speed(0.5); 00097 motor3.speed(0.5); 00098 Thread::wait(2000); 00099 motor1.speed(-0.5); 00100 motor2.speed(-0.5); 00101 motor3.speed(-0.5); 00102 Thread::wait(2000); 00103 } 00104 }
Generated on Sun Jul 17 2022 00:27:19 by
1.7.2
