Last active
December 18, 2022 18:03
-
-
Save broccoli1002/54aaaad1683b1a339d34b4851a9c79b6 to your computer and use it in GitHub Desktop.
report5-2
This file contains 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
#include <SPI.h> | |
#include <MFRC522.h> | |
#include "LedControl.h" | |
#define CARDUID "c3 85 14 21" | |
#define TAGUID "33 6a 38 1f" | |
constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above | |
constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above | |
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance | |
/* | |
Now we need a LedControl to work with. | |
***** These pin numbers will probably not work with your hardware ***** | |
pin 4 is connected to the DataIn | |
pin 2 is connected to LOAD(CS) | |
pin 3 is connected to the CLK | |
We have only a single MAX72XX. | |
*/ | |
LedControl lc=LedControl(4,2,3,1); | |
unsigned long delaytime1=500; | |
unsigned long delaytime2=50; | |
void setup() { | |
Serial.begin(9600); // Initialize serial communications with the PC | |
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) | |
SPI.begin(); // Init SPI bus | |
mfrc522.PCD_Init(); // Init MFRC522 | |
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details | |
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); | |
/* | |
The MAX72XX is in power-saving mode on startup, | |
we have to do a wakeup call | |
*/ | |
lc.shutdown(0,false); | |
/* Set the brightness to a medium values */ | |
lc.setIntensity(0,8); | |
/* and clear the display */ | |
lc.clearDisplay(0); | |
} | |
void loop() { | |
// Look for new cards | |
if ( ! mfrc522.PICC_IsNewCardPresent()) { | |
return; | |
} | |
// Select one of the cards | |
if ( ! mfrc522.PICC_ReadCardSerial()) { | |
return; | |
} | |
// Dump debug info about the card; PICC_HaltA() is automatically called | |
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); | |
// 取得したUIDをbyteに変換してから、Stringに変換する | |
String strBuf[mfrc522.uid.size]; | |
for (byte i = 0; i < mfrc522.uid.size; i++) { | |
strBuf[i] = String(mfrc522.uid.uidByte[i], HEX); // (E)using a constant integer | |
if(strBuf[i].length() == 1){ // 1桁の場合は先頭に0を追加 | |
strBuf[i] = "0" + strBuf[i]; | |
} | |
} | |
String strUID = strBuf[0] + " " + strBuf[1] + " " + strBuf[2] + " " + strBuf[3]; | |
Serial.println(strUID); | |
// 大文字小文字関係なく比較 | |
if ( strUID.equalsIgnoreCase(CARDUID) ){ | |
Serial.println("1"); | |
rows(); | |
}else if(strUID.equalsIgnoreCase(TAGUID) ){ | |
Serial.println("2"); | |
columns(); | |
}else{ | |
Serial.println("3"); | |
single(); | |
} | |
} | |
/* | |
This function lights up a some Leds in a row. | |
The pattern will be repeated on every row. | |
The pattern will blink along with the row-number. | |
row number 4 (index==3) will blink 4 times etc. | |
*/ | |
void rows() { | |
for(int row=0;row<8;row++) { | |
delay(delaytime2); | |
lc.setRow(0,row,B10100000); | |
delay(delaytime2); | |
lc.setRow(0,row,(byte)0); | |
for(int i=0;i<row;i++) { | |
delay(delaytime2); | |
lc.setRow(0,row,B10100000); | |
delay(delaytime2); | |
lc.setRow(0,row,(byte)0); | |
} | |
} | |
} | |
/* | |
This function lights up a some Leds in a column. | |
The pattern will be repeated on every column. | |
The pattern will blink along with the column-number. | |
column number 4 (index==3) will blink 4 times etc. | |
*/ | |
void columns() { | |
for(int col=0;col<8;col++) { | |
delay(delaytime2); | |
lc.setColumn(0,col,B10100000); | |
delay(delaytime2); | |
lc.setColumn(0,col,(byte)0); | |
for(int i=0;i<col;i++) { | |
delay(delaytime2); | |
lc.setColumn(0,col,B10100000); | |
delay(delaytime2); | |
lc.setColumn(0,col,(byte)0); | |
} | |
} | |
} | |
/* | |
This function will light up every Led on the matrix. | |
The led will blink along with the row-number. | |
row number 4 (index==3) will blink 4 times etc. | |
*/ | |
void single() { | |
for(int row=0;row<8;row++) { | |
for(int col=0;col<8;col++) { | |
delay(delaytime2); | |
lc.setLed(0,row,col,true); | |
delay(delaytime2); | |
for(int i=0;i<col;i++) { | |
lc.setLed(0,row,col,false); | |
delay(delaytime2); | |
lc.setLed(0,row,col,true); | |
delay(delaytime2); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment