2014-10-04 123 views
0

對於C++編程的世界,我還是很新的東西,所以對我來說很容易。哈哈Arduino多點擊功能混淆

我想製作一個系統來跟蹤我父親最喜歡的遊戲之一的高分。我正在使用LCD屏幕和3x4鍵盤進行評分輸入。我想在小鍵盤上添加一個多點觸控功能,這樣就可以像用於存儲用戶首字母的電話小鍵盤一樣。我創建了一個存儲分數的函數(它可能不是最好的方法,但它的工作原理,關於如何改進的意見將不勝感激。)我甚至不知道從哪一個開始。我已經看過在Arduino的鍵盤庫的動態鍵盤的例子,但我覺得我可能已經被咬的比我更可以嚼 我的代碼如下:

#include <SoftwareSerial.h> 
#include "Keypad.h" 

// Create a software serial port! 
SoftwareSerial lcd = SoftwareSerial(11,10); 
char scoreinput[] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; 
int counter = -2; 
int counter2=0; 
uint8_t red, green, blue; 



const byte ROWS = 4; //four rows 
const byte COLS = 3; //three columns 
char keys[ROWS][COLS] = { 
{'1','2','3'}, 
{'4','5','6'}, 
{'7','8','9'}, 
{'*','0','#'} 
}; 
byte rowPins[ROWS] = {5, 6, 7, 8}; //connect to the row pinouts of the keypad 
byte colPins[COLS] = {2, 3, 4}; //connect to the column pinouts of the keypad 

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); 


void setup() { 
lcd.begin(9600); 
Serial.begin(9600); 

lcd.write(0xFE); //clear display 
lcd.write(0x58); 
delay(10); 
lcd.print("****PinScore*******************"); 
lcd.write(0xFE);//set cursor at home 
lcd.write(0x48); 
delay(5000); 



lcd.write(0xFE); //clear display 
lcd.write(0x58); 
delay(10); 
lcd.print("New High Score?"); 
lcd.write(0xFE); 
lcd.write(0x47); 
lcd.write((uint8_t)2); 
lcd.print(" Press  \"#\""); 
delay(5000); 

lcd.write(0xFE); //clear display 
lcd.write(0x58); 
delay(10); 
lcd.print("Display Scores?"); 
lcd.write(0xFE); 
lcd.write(0x47); 
lcd.write((uint8_t)2); 
lcd.print(" Press  \"*\""); 
delay(5000); 

lcd.write(0xFE); //clear display 
lcd.write(0x58); 
lcd.print("  Press  "); 
lcd.write(0xFE); 
lcd.write(0x47); 
lcd.write((uint8_t)2); 
lcd.print(" \"*\" or \"#\" "); 
} 


void loop() { 



char key = keypad.getKey(); 

if (key != NO_KEY){ 
Serial.print(key); 
lcd.print(key); 
counter++; 
counter2++; 
scoreinput[counter]=(key); 
} 

switch (key == '#'){ 
    case 1: 




lcd.write(0xFE); //clear display 
lcd.write(0x58); 
delay(10); 
lcd.print("Enter Your New High Score"); 
delay(3000); 
lcd.write(0xFE); //clear display 
lcd.write(0x58); 
lcd.print("Press \"#\" At Any Time To Reset"); 
delay(3000); 
lcd.write(0xFE); //clear display 
lcd.write(0x58); 
lcd.print("Enter High Score:"); 


lcd.write(0xFE); 
lcd.write(0x47); 
lcd.write((uint8_t)18); 
lcd.print(key); 

if (counter==8){ 
    break; 
} 
} 

if (counter==8){ 
lcd.write(0xFE); //clear display 
lcd.write(0x58); 
delay(1000); 
lcd.print(scoreinput[0]); 
lcd.print(scoreinput[1]); 
lcd.print(scoreinput[2]); 
lcd.print(","); 
lcd.print(scoreinput[3]); 
lcd.print(scoreinput[4]); 
lcd.print(scoreinput[5]); 
lcd.print(","); 
lcd.print(scoreinput[6]); 
lcd.print(scoreinput[7]); 
lcd.print(scoreinput[8]); 
counter=-2; 
delay(3000); 
lcd.write(0xFE); //clear display 
lcd.write(0x58); 
lcd.print("Enter your  Initals:"); 
    } 
while (counter2>10){ 
if (key == '2'){ 
//this is where the multi tap function would be called to allow users to enter their intials 

} 
} 

回答

0

你只需要一個定時器來測量時間,因爲最後一個鍵入口。如果從最後一次擊鍵以來它已經大於一段時間(或許是1秒),或者如果該鍵不同於最後一次按鍵,則輸入一個新的字符(該鍵的第一個字符; 2 = A,3 = D等),否則它會增加字符(帶有環繞,A => B,B => C,C => A)。因此「234」進入「ADG」,「222」進入「C」,但「2(延遲)22」進入「AB」。