
【背景】 「(右手が忙しいので,)足でEnterキーを入力したい.」という依頼があり,製作した.これ以上詳しく理由を聞くことはなかった・・・(お察し下さい). 【ハードウェア】 レーシングゲーム用コントローラのペダルに,マイクロスイッチを取り付けた.アクセルペダルやブレーキペダルを踏むと,それぞれのマイクロスイッチが押される.マイクロスイッチはプルアップで接続されている. 【動作】 アクセルペダルを踏むとEnterが入力され,ブレーキペダルを踏むと下にスクロールする.
Dependencies: USBDevice TextLCD mbed
main.cpp
00001 #include "mbed.h" 00002 #include "USBMouseKeyboard.h" 00003 #include "TextLCD.h" 00004 00005 USBMouseKeyboard pedal; 00006 00007 TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d0-d3 00008 00009 DigitalOut a_led(LED1); 00010 DigitalOut b_led(LED2); 00011 00012 DigitalOut powerA(p13); 00013 DigitalOut powerB(p14); 00014 00015 /* 00016 InterruptIn Accel(p12); 00017 InterruptIn Brake(p29); 00018 */ 00019 00020 DigitalIn Accel(p9); 00021 DigitalIn Brake(p18); 00022 00023 int accel_flag; // push? 00024 int brake_flag; // push? 00025 00026 /* 00027 void Afall(){ 00028 accel_flag = 0; 00029 wait(0.1); 00030 } 00031 void Arise(){ 00032 accel_flag++; 00033 wait(0.1); 00034 } 00035 void Bfall(){ 00036 brake_flag = 0; 00037 wait(0.1); 00038 00039 } 00040 void Brise(){ 00041 brake_flag++; 00042 wait(0.1); 00043 } 00044 */ 00045 00046 00047 int main(void) { 00048 int i=0; 00049 00050 /* debug */ 00051 a_led = 1; 00052 b_led = 1; 00053 lcd.printf("hello\n"); 00054 00055 00056 /* Initialize */ 00057 powerA = 1; 00058 powerB = 1; 00059 00060 accel_flag = 0; 00061 brake_flag = 0; 00062 00063 00064 /* main Loop */ 00065 while (1) { 00066 /* debug */ 00067 a_led = accel_flag; 00068 b_led = brake_flag; 00069 00070 00071 /* sensing */ 00072 if(Accel > 0.5){ 00073 accel_flag = 1; 00074 }else{ 00075 accel_flag = 0; 00076 } 00077 if(Brake > 0.5){ 00078 brake_flag = 1; 00079 }else{ 00080 brake_flag = 0; 00081 } 00082 00083 00084 /* keyboard input */ 00085 if(i > 10){ 00086 lcd.cls(); 00087 if(accel_flag > 0){ 00088 lcd.locate(0,0); lcd.printf("A:%d",accel_flag); 00089 pedal.printf("\n"); 00090 } 00091 00092 if(brake_flag > 0){ 00093 //pedal.keyCode('', KEY_CTRL); 00094 lcd.locate(0,1); lcd.printf("B:%d",brake_flag); 00095 pedal.scroll(127); // -128 ~ 127 00096 } 00097 i = 0; 00098 } 00099 00100 i++; 00101 wait(0.1); 00102 } 00103 00104 return 0; 00105 /* Accel.fall(&Afall); 00106 Accel.rise(&Arise); 00107 Brake.fall(&Bfall); 00108 Brake.rise(&Brise); 00109 */ 00110 00111 00112 }
Generated on Fri Jul 15 2022 23:58:51 by
