Skip to content

Conversation

@taka-sho
Copy link

はじめに

元塾高電工研の者です.うるさいOBですが,なんとなく雑感をまとめてみました.

概要

基本的なところでいい感じに書直せそうなところを直してみました.修正箇所ごとにコメント書いておきます.

display.setTextColor(WHITE);//出力する文字の色
display.setCursor(0, 0);//カーソル位置の指定
display.println("Nocard");// ディスプレイへ表示する文字列
resetDisplay()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何回も初期化すると思うので,画面の初期化処理を関数にする.関数の内容は

void resetDisplay () {
  display.clearDisplay();
  display.setCursor(0, 0);
  display.setTextColor(WHITE);
}

display.setCursor(0, 0);//カーソル位置の指定
display.println("Nocard");// ディスプレイへ表示する文字列
resetDisplay()
printlnText("Nocard", 2);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目的は

  • 何回か処理するので関数にまとめる
  • 画面に映す文字の内容と大きさを紐付けする
    の2点.関数の内容は
void printlnText (String text, int textSize) {
  display.setTextSize(textSize)
  display.println(text)
}

今回は display.println()display.print() のそれぞれに対応する関数を作っています


Message = "No mode";
NUMBER = "000";
NUMBER = 000;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8行目int NUMBER と宣言しているので,辻褄が合わないなというお気持ち

if ( ! mfrc522.PICC_ReadCardSerial()) return;// Mifareカードのデータ読み込み(読み取れなければ終了し、loop関数を繰り返す)

if (
! mfrc522.PICC_IsNewCardPresent() || // Mifareカードのデータ読み込み
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

論理演算子を用いて簡潔に.見た目もよくなるし,loop関数で分岐する回数が半分になるので処理的にも優しくなりまする



if ( 85 < mode && mode < 170 ) {
} else if ( 85 < mode && mode < 170 ) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if を使おうの会


if (pointDeduct == 0) {
NUMBER = NUMBER - 10;
NUMBER -= 10;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a = a - ba -= b と書き換えられるのだ!変数名を2回書かなくてもよくなる!!べんり!!!

display.setTextColor(WHITE);
display.print("cardUID = ");
display.println(strUID);
} else {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strUID == UID

  • 一致する
  • 一致しない
    の2種類の状況以外はありえないので, else を使った方が明示的.加えてメモリ消費も少なくなる.

@taka-sho
Copy link
Author

検証していないのでこのプログラムが動くかはわかりませんが,方向性だけでも受け取っていただきたい気持ちです!
開発頑張ってください!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant