-
Notifications
You must be signed in to change notification settings - Fork 1
[DO NOT MERGE] 参考に #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| display.setTextColor(WHITE);//出力する文字の色 | ||
| display.setCursor(0, 0);//カーソル位置の指定 | ||
| display.println("Nocard");// ディスプレイへ表示する文字列 | ||
| resetDisplay() |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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カードのデータ読み込み |
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a = a - b は a -= b と書き換えられるのだ!変数名を2回書かなくてもよくなる!!べんり!!!
| display.setTextColor(WHITE); | ||
| display.print("cardUID = "); | ||
| display.println(strUID); | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strUID == UID は
- 一致する
- 一致しない
の2種類の状況以外はありえないので,elseを使った方が明示的.加えてメモリ消費も少なくなる.
|
検証していないのでこのプログラムが動くかはわかりませんが,方向性だけでも受け取っていただきたい気持ちです! |
はじめに
元塾高電工研の者です.うるさいOBですが,なんとなく雑感をまとめてみました.
概要
基本的なところでいい感じに書直せそうなところを直してみました.修正箇所ごとにコメント書いておきます.