awesome
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Txx.uo.ino 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3. #define SS_PIN 10
  4. #define RST_PIN 9
  5. #define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
  6. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
  7. #include <LiquidCrystal_I2C.h>
  8. //LiquidCrystal_I2C lcd(0x38, BACKLIGHT_PIN, POSITIVE); // Set the LCD I2C address
  9. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
  10. const int RFIDled = 6;
  11. const int RFIDSound = 5;
  12. const int RFIDbin = 3;
  13. const int signalIN = A0;
  14. const int TextKnob = A1;
  15. const int textSound = A2;
  16. long randNumber;
  17. void setup()
  18. {
  19. Serial.begin(9600); // Initiate a serial communication
  20. SPI.begin(); // Initiate SPI bus
  21. lcd.begin(16, 2); // initialize the lcd
  22. mfrc522.PCD_Init(); // Initiate MFRC522
  23. Serial.println();
  24. pinMode(RFIDled, OUTPUT);
  25. pinMode(RFIDSound, OUTPUT);
  26. pinMode(RFIDbin, OUTPUT);
  27. pinMode(signalIN, INPUT);
  28. pinMode(TextKnob, INPUT);
  29. pinMode(textSound, OUTPUT);
  30. }
  31. void readCard() {
  32. // Look for new cards
  33. if ( ! mfrc522.PICC_IsNewCardPresent())
  34. {
  35. return;
  36. }
  37. // Select one of the cards
  38. if ( ! mfrc522.PICC_ReadCardSerial())
  39. {
  40. return;
  41. }
  42. //Show UID on serial monitor
  43. Serial.print("UID tag :");
  44. String content = ""; // for tag + sound
  45. String binary = ""; // for binary + LED
  46. for (int i = 0; i < mfrc522.uid.size; i++)
  47. {
  48. Serial.print(mfrc522.uid.uidByte[i], DEC);
  49. content.concat(String(mfrc522.uid.uidByte[i], DEC));
  50. if (content.charAt(i) == '0') {
  51. tone(RFIDSound, 40, 2250);
  52. delay(100);
  53. }
  54. else if (content.charAt(i) == '1') {
  55. tone(RFIDSound, 15, 2250);
  56. delay(100);
  57. }
  58. else if (content.charAt(i) == '2') {
  59. tone(RFIDSound, 25, 1500);
  60. delay(100);
  61. }
  62. else if (content.charAt(i) == '3') {
  63. tone(RFIDSound, 17, 150);
  64. delay(100);
  65. }
  66. else if (content.charAt(i) == '4') {
  67. tone(RFIDSound, 30, 1000);
  68. delay(100);
  69. }
  70. else if (content.charAt(i) == '5') {
  71. tone(RFIDSound, 27, 1590);
  72. delay(100);
  73. }
  74. else if (content.charAt(i) == '6') {
  75. tone(RFIDSound, 28, 1500);
  76. delay(100);
  77. }
  78. else if (content.charAt(i) == '7') {
  79. tone(RFIDSound, 10, 1500);
  80. delay(100);
  81. }
  82. else if (content.charAt(i) == '8') {
  83. tone(RFIDSound, 13, 1050);
  84. delay(100);
  85. }
  86. else if (content.charAt(i) == '9') {
  87. tone(RFIDSound, 7, 1000);
  88. delay(100);
  89. }
  90. }
  91. for (int b = 0; b < mfrc522.uid.size; b++)
  92. {
  93. Serial.println(mfrc522.uid.uidByte[b], BIN);
  94. char r = mfrc522.uid.uidByte[b];
  95. for (int j = 8; j >= 0; j--) {
  96. if CHECK_BIT(r, j) {
  97. digitalWrite(RFIDled, HIGH);
  98. digitalWrite(RFIDbin, HIGH);
  99. delay(100);
  100. } else {
  101. digitalWrite(RFIDled, LOW);
  102. digitalWrite(RFIDbin, LOW);
  103. delay(100);
  104. }
  105. delay(100);
  106. }
  107. }
  108. Serial.println();
  109. delay(100);
  110. }
  111. //Q-code questions
  112. const char *Qs[] = {
  113. "",
  114. "",
  115. "QRB?:How far are you from my station?",
  116. "QRL?:Are you busy?",
  117. "QRZ?:Who is calling me?",
  118. "QRH?:Does my frequency vary?",
  119. "QRI?:How is the tone of my transmission?",
  120. "QRK?:What is the readability of my signals?",
  121. "QRM?:Do you have interference?",
  122. "QRN?:Are you troubled by static noise?",
  123. "QRQ?:Shall I send faster?",
  124. "QRT?:Shall I cease or suspend operation?",
  125. "QRU?:Have you anything for me?",
  126. "QRV?:Are you ready?",
  127. "QRX?:Shall I standby?",
  128. "QSA?:What is the strength of my signals?",
  129. "QSB?:Are my signals fading?",
  130. "QSD?:Is my keying defective?",
  131. "QSL?:Can you acknowledge receipt?"
  132. };
  133. //Q-code answers/statements
  134. const char *As[] = {
  135. "QRH:Your frequency varies.",
  136. "QRL:I am busy. Please do not interfere.",
  137. "QRM:I have interference.",
  138. "QRM:I am troubled by static noise.",
  139. "QRO:Please increase transmit power.",
  140. "QRQ:Please send faster.",
  141. "QRS:Please send more slowly",
  142. "QRT:I am suspending operation.",
  143. "QRU:I have nothing for you.",
  144. "QRV:I am ready.",
  145. "QRX:Please standby.",
  146. "QSB:Your signals are fading.",
  147. "QSD:Your keying is defective.",
  148. "QSK:I can hear you between my signals (while transmitting); break in on my transmission.",
  149. "QSL:I am acknowledging receipt.",
  150. "QSM:Repeat the last telegram which you sent me",
  151. "QSY:Please change transmission frequency.",
  152. "QSZ:Send each word or group twice."
  153. };
  154. void loop()
  155. {
  156. readCard();
  157. int textnumber;
  158. int text = analogRead(TextKnob);
  159. textnumber = map(text, 1, 1023, 0, 18);
  160. if (textnumber > 1) { //when the knob is turned from the 'position 0'
  161. Serial.println(Qs[textnumber]);
  162. String question = Qs[textnumber];
  163. lcd.setCursor(0, 0); //Set the lcd cursor to the upper left corner
  164. lcd.print(Qs[textnumber]); //Display the specific Q-question on the fisrt row of LCD
  165. for (int positionCounter = 0; positionCounter < question.length(); positionCounter++) {
  166. lcd.scrollDisplayLeft(); //Q-question scrolls to the left
  167. delay(230);
  168. }
  169. char* specQs = Qs[textnumber];
  170. // loop over each character of question
  171. for (int a = 0; a < strlen(specQs); a++ ) {
  172. char c = specQs[a];
  173. //Serial.print(c);
  174. //Serial.print(" ");
  175. Serial.print(specQs[a], BIN);
  176. //Serial.println();
  177. // sonify the bits...
  178. for (int i = 7; i >= 0; i--) {
  179. if CHECK_BIT(c, i) {
  180. tone(textSound, 440, 100);
  181. } else {
  182. tone(textSound, 220, 100);
  183. }
  184. delay(100);
  185. }
  186. }
  187. }
  188. // give an answer
  189. randNumber = random(0, 17);
  190. int readSignal = digitalRead(signalIN);
  191. String randomQ = As[randNumber];
  192. if (readSignal) { //If the module receives a signal via A2 o4 input channel...
  193. Serial.println(As[randNumber]);
  194. lcd.setCursor(0, 1); //Set the lcd cursor to the lower left corner
  195. lcd.print(randomQ); //Displayes a random Q-answer from the answers array
  196. for (int counter = 0; counter < randomQ.length(); counter++) {
  197. lcd.scrollDisplayLeft(); //Q-answer dissapears in the left side of the LCD
  198. delay(230);
  199. }
  200. }
  201. delay(500);
  202. }