Open
Conversation
taka-sho
commented
Feb 21, 2019
| display.setTextColor(WHITE);//出力する文字の色 | ||
| display.setCursor(0, 0);//カーソル位置の指定 | ||
| display.println("Nocard");// ディスプレイへ表示する文字列 | ||
| resetDisplay() |
Author
There was a problem hiding this comment.
何回も初期化すると思うので,画面の初期化処理を関数にする.関数の内容は
void resetDisplay () {
display.clearDisplay();
display.setCursor(0, 0);
display.setTextColor(WHITE);
}
| display.setCursor(0, 0);//カーソル位置の指定 | ||
| display.println("Nocard");// ディスプレイへ表示する文字列 | ||
| resetDisplay() | ||
| printlnText("Nocard", 2); |
Author
There was a problem hiding this comment.
目的は
- 何回か処理するので関数にまとめる
- 画面に映す文字の内容と大きさを紐付けする
の2点.関数の内容は
void printlnText (String text, int textSize) {
display.setTextSize(textSize)
display.println(text)
}
今回は display.println() と display.print() のそれぞれに対応する関数を作っています
|
|
||
| Message = "No mode"; | ||
| NUMBER = "000"; | ||
| NUMBER = 000; |
| if ( ! mfrc522.PICC_ReadCardSerial()) return;// Mifareカードのデータ読み込み(読み取れなければ終了し、loop関数を繰り返す) | ||
|
|
||
| if ( | ||
| ! mfrc522.PICC_IsNewCardPresent() || // Mifareカードのデータ読み込み |
Author
There was a problem hiding this comment.
論理演算子を用いて簡潔に.見た目もよくなるし,loop関数で分岐する回数が半分になるので処理的にも優しくなりまする
|
|
||
|
|
||
| if ( 85 < mode && mode < 170 ) { | ||
| } else if ( 85 < mode && mode < 170 ) { |
|
|
||
| if (pointDeduct == 0) { | ||
| NUMBER = NUMBER - 10; | ||
| NUMBER -= 10; |
Author
There was a problem hiding this comment.
a = a - b は a -= b と書き換えられるのだ!変数名を2回書かなくてもよくなる!!べんり!!!
| display.setTextColor(WHITE); | ||
| display.print("cardUID = "); | ||
| display.println(strUID); | ||
| } else { |
Author
There was a problem hiding this comment.
strUID == UID は
- 一致する
- 一致しない
の2種類の状況以外はありえないので,elseを使った方が明示的.加えてメモリ消費も少なくなる.
Author
|
検証していないのでこのプログラムが動くかはわかりませんが,方向性だけでも受け取っていただきたい気持ちです! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
はじめに
元塾高電工研の者です.うるさいOBですが,なんとなく雑感をまとめてみました.
概要
基本的なところでいい感じに書直せそうなところを直してみました.修正箇所ごとにコメント書いておきます.