PR

K3NG CW Keyer、受信送信5文字エコーバック練習機能を改造 – その2

また少し改造した。今回は、成功数と失敗数の表示機能追加。5文字連続正解した際に、下の写真のように表示する。

二行目の左が5文字連続正解した数。右が累計の不正解数(sはsuccess、fはfailの意)。この表示を加えたことによって、多少はゲーム性が出て、目標を持ちやすくなったかなと思う。なお、それぞれ16ビットのカウンタなので、65535を超えると0に戻る(はず。そこまでは動作確認していない)。

--- D:/tmp1/k3ng_keyer/k3ng_keyer.ino	Tue May 31 01:30:52 2022
+++ D:/tmp2/k3ng_keyer/k3ng_keyer.ino	Tue Jun 27 22:47:18 2022
@@ -8249,2 +8257,6 @@
   // char word_buffer[10];
+  word count_success, count_fail;
+
+ 	count_success = 0;
+	count_fail = 0;
 
@@ -8460,4 +8472,6 @@
               loop2 = 0;
+              count_success++;
               if (correct_answer_led) digitalWrite(correct_answer_led, HIGH);             // set the correct answer LED high
               #ifdef FEATURE_DISPLAY
+                /*
                 lcd_center_print_timed("Success!", 0, default_display_msg_delay);
@@ -8465,2 +8479,10 @@
                 if (LCD_COLUMNS < 17) lcd_center_print_timed("5 char correct", 1, default_display_msg_delay);
+                */
+                if (LCD_COLUMNS > 17) {
+                	lcd_center_print_timed("5 characters correct", 0, default_display_msg_delay);
+                }
+                else if (LCD_COLUMNS < 17) {
+                	lcd_center_print_timed("5 char correct", 0, default_display_msg_delay);
+                }
+                lcd_center_print_timed(String(count_success)+" "+"s"+" "+String(count_fail)+" "+"f", 1, (default_display_msg_delay * 2));
               #endif                                                                      // FEATURE_DISPLAY
@@ -8487,2 +8509,3 @@
           } else {                                                                        // we get here if the character entered is wrong
+            count_fail++;
             if (wrong_answer_led) digitalWrite(wrong_answer_led, HIGH);                   // set the wrong answer LED high

やっていることは単純で、成功と失敗のカウンタをそれぞれ作って数え、5文字連続正解後にそれを表示しているだけ。

String(count_success)+” “+”s”+” “+String(count_fail)+” “+”f”

この妙ちくりんなコードはグローバル変数領域が食いつぶされないようにするため。本当は素直に” s “と” f”と書きたいのだけど、そうするとコンパイル時にグローバル変数領域が少なくなったと警告される。上のように書くと空白” “が再利用されるのかグローバル変数領域の使用量が少なくて済み、警告が出ない。文字列リテラルをRAM領域に確保する理由がわからない…。

自作
この記事のタイトルとURLをコピーする
スポンサーリンク
スポンサーリンク
スポンサーリンク

コメント