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 /* ELEC2645 Gamepad Test 00002 * 2nd Generation 00003 * January 2020 00004 * Dr Craig A. Evans & Joshua Davy 00005 */ 00006 00007 00008 00009 // Includes 00010 #include "mbed.h" 00011 #include "Gamepad.h" 00012 #include "N5110.h" 00013 00014 00015 // objects 00016 Gamepad pad; 00017 N5110 lcd; 00018 00019 void check_buttons(); 00020 00021 int main() 00022 { 00023 lcd.init(); 00024 lcd.setContrast(0.5); 00025 pad.init(); 00026 00027 lcd.backLightOn(); 00028 lcd.printString("Hello Gamepad!",0,0); 00029 lcd.refresh(); 00030 pad.tone(1000.0,2.0); 00031 wait_ms(2000); 00032 00033 lcd.clear(); 00034 lcd.printString("Turn Pot 1",0,0); 00035 lcd.printString(" to set",0,1); 00036 lcd.printString(" contrast",0,2); 00037 lcd.refresh(); 00038 00039 // turn pot 1 during this 5 second period to tweak contrast 00040 for (int i = 0; i < 500; i++) { 00041 lcd.setContrast( pad.read_pot1()); 00042 wait_ms(10); 00043 } 00044 00045 lcd.clear(); 00046 lcd.printString("LED test",0,0); 00047 lcd.refresh(); 00048 00049 // flash LEDs 00050 for (int i = 0; i < 20; i++) { 00051 pad.leds_on(); 00052 wait_ms(200); 00053 pad.leds_off(); 00054 wait_ms(200); 00055 } 00056 00057 // PWM brightness (0 to 100%) 00058 for (float x = 0.0f; x <= 1.0f ; x+=0.1f) { 00059 pad.leds(x); 00060 wait_ms(500); 00061 } 00062 00063 pad.leds_off(); 00064 00065 for (int n = 1; n <= 6; n++) { 00066 pad.led(n,1.0); // led, full-brightness 00067 wait_ms(1000); 00068 } 00069 00070 while(1) { 00071 pad.leds_off(); 00072 lcd.clear(); 00073 lcd.setContrast( pad.read_pot1()); 00074 printf("%f , %f\n",pad.read_pot1(),pad.read_pot2()); 00075 check_buttons(); 00076 Vector2D coord = pad.get_mapped_coord(); 00077 float x = coord.x; 00078 float y = coord.y; 00079 00080 lcd.drawCircle(WIDTH/2+int(20*x),HEIGHT/2-int(20*y),3,FILL_BLACK); 00081 lcd.drawCircle(WIDTH/2,HEIGHT/2,20,FILL_TRANSPARENT); // x,y,radius,transparent with outline 00082 00083 lcd.refresh(); 00084 wait_ms(100); 00085 } 00086 } 00087 00088 void check_buttons() 00089 { 00090 if ( pad.A_pressed()) { 00091 lcd.printChar('A',0,0); 00092 pad.led(1,1.0); 00093 pad.tone(1000.0,0.2); 00094 printf("A pressed\n"); 00095 } 00096 if ( pad.B_pressed()) { 00097 lcd.printChar('B',0,1); 00098 pad.led(2,1.0); 00099 pad.tone(1000.0,0.2); 00100 printf("B pressed\n"); 00101 } 00102 if ( pad.X_pressed()) { 00103 lcd.printChar('X',0,2); 00104 pad.led(3,1.0); 00105 pad.tone(1000.0,0.2); 00106 printf("X pressed\n"); 00107 } 00108 if ( pad.Y_pressed() ) { 00109 lcd.printChar('Y',0,3); 00110 pad.led(4,1.0); 00111 pad.tone(1000.0,0.2); 00112 printf("Y pressed\n"); 00113 } 00114 if ( pad.start_pressed()) { 00115 lcd.printChar('S',78,2); 00116 pad.led(5,1.0); 00117 pad.tone(1000.0,0.2); 00118 printf("Start pressed\n"); 00119 } 00120 00121 00122 }
Generated on Sat Jul 16 2022 16:00:56 by
1.7.2