RFID Key Ring Toss




Arduino Mega
4 Digit 7 Segment Display Module
LSR Module
Neopixel Strip
LM2596 Voltage Regulator

  1. // hackable rfid key ring toss
  2. // pkvi
  3. #include <TM1637Display.h>
  4. #define CLK 5
  5. #define DIO 6
  6. TM1637Display display = TM1637Display(CLK, DIO);
  7. #include "FastLED.h"
  8. #define NUM_LEDS 212
  9. #define LED_TYPE WS2812B
  10. #define COLOR_ORDER GRB
  11. CRGB leds[NUM_LEDS];
  12. const int NEO = 7;
  13. int w, y, z;
  14. #include <MFRC522.h>
  15. #include <SPI.h>
  16. #define SS_1_PIN 8
  17. #define SS_2_PIN 11
  18. #define SS_3_PIN 10
  19. #define SS_4_PIN 9
  20. #define RST_PIN 12
  21. MFRC522 rfid100(SS_1_PIN, RST_PIN);
  22. MFRC522 rfid150(SS_2_PIN, RST_PIN);
  23. MFRC522 rfid200(SS_3_PIN, RST_PIN);
  24. MFRC522 rfid250(SS_4_PIN, RST_PIN);
  25. const int photoresistor = 3;
  26. int term;
  27. int loc100;
  28. int loc150;
  29. int loc200;
  30. int loc250;
  31. void setup() {
  32. Serial.begin(9600);
  33. FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  34. display.clear();
  35. display.setBrightness(4);
  36. SPI.begin();
  37. rfid100.PCD_Init();
  38. rfid150.PCD_Init();
  39. rfid200.PCD_Init();
  40. rfid250.PCD_Init();
  41. pinMode(photoresistor, INPUT);
  42. neo_win(0, 0, 255);
  43. }
  44. void loop() {
  45. neo_loop(0, 0, 255);
  46. }
  47. void neo_loop(int r, int g, int b) {
  48. z = random(5, 60);
  49. for (w = 0; w < NUM_LEDS; w++) {
  50. pixel(r, g, b, w);
  51. display.clear();
  52. display.showNumberDec(w);
  53. if (w < 5) {
  54. if (w == 0) {
  55. y = NUM_LEDS - 5;
  56. pixel(0, 0, 0, y);
  57. } else if (w == 1) {
  58. y = NUM_LEDS - 4;
  59. pixel(0, 0, 0, y);
  60. } else if (w == 2) {
  61. y = NUM_LEDS - 3;
  62. pixel(0, 0, 0, y);
  63. } else if (w == 3) {
  64. y = NUM_LEDS - 2;
  65. pixel(0, 0, 0, y);
  66. } else if (w == 4) {
  67. y = NUM_LEDS - 1;
  68. pixel(0, 0, 0, y);
  69. } else if (w == 5) {
  70. y = NUM_LEDS;
  71. pixel(0, 0, 0, y);
  72. }
  73. } else {
  74. y = w - 5;
  75. pixel(0, 0, 0, y);
  76. }
  77. // tom servo
  78. if (digitalRead(photoresistor) == LOW) {
  79. for (int m = 500; m > 0; m--) {
  80. display.clear();
  81. display.showNumberDec(m);
  82. }
  83. }
  84. // 100
  85. if (w < 42 || w > 183) {
  86. pixel(255, 125, 0, 47);
  87. }
  88. if (w == 41) {
  89. pixel(0, 0, 0, 47);
  90. check_rfid();
  91. // win
  92. while (loc100 == 1) {
  93. display.clear();
  94. display.showNumberDec(100);
  95. neo_win(0, 255, 0);
  96. check_rfid();
  97. }
  98. // lose
  99. while (loc150 == 1 || loc200 == 1 || loc250 == 1) {
  100. display.clear();
  101. display.showNumberDec(-0);
  102. neo_lose(255, 0, 0);
  103. check_rfid();
  104. }
  105. z = random(5, 60);
  106. }
  107. // 200
  108. if (w < 67 && w > 41) {
  109. pixel(255, 125, 0, 63);
  110. }
  111. if (w == 66) {
  112. pixel(0, 0, 0, 63);
  113. check_rfid();
  114. // win
  115. while (loc200 == 1) {
  116. display.clear();
  117. display.showNumberDec(200);
  118. neo_win(0, 255, 0);
  119. check_rfid();
  120. }
  121. // lose
  122. while (loc100 == 1 || loc200 == 1 || loc250 == 1) {
  123. display.clear();
  124. display.showNumberDec(-0);
  125. neo_lose(255, 0, 0);
  126. check_rfid();
  127. }
  128. z = random(5, 60);
  129. }
  130. // 250
  131. if (w < 139 && w > 66) {
  132. pixel(255, 125, 0, 134);
  133. }
  134. if (w == 138) {
  135. pixel(0, 0, 0, 134);
  136. check_rfid();
  137. // win
  138. while (loc250 == 1) {
  139. display.clear();
  140. display.showNumberDec(250);
  141. neo_win(0, 255, 0);
  142. check_rfid();
  143. }
  144. // lose
  145. while (loc100 == 1 || loc150 == 1 || loc200 == 1) {
  146. display.clear();
  147. display.showNumberDec(-0);
  148. neo_lose(255, 0, 0);
  149. check_rfid();
  150. }
  151. z = random(5, 60);
  152. }
  153. // 150
  154. if (w < 184 && w > 138) {
  155. pixel(255, 125, 0, 177);
  156. }
  157. if (w == 183) {
  158. pixel(0, 0, 0, 177);
  159. check_rfid();
  160. // win
  161. while (loc150 == 1) {
  162. display.clear();
  163. display.showNumberDec(150);
  164. neo_win(0, 255, 0);
  165. check_rfid();
  166. }
  167. // lose
  168. while (loc100 == 1 || loc200 == 1 || loc250 == 1) {
  169. display.clear();
  170. display.showNumberDec(-0);
  171. neo_lose(255, 0, 0);
  172. check_rfid();
  173. }
  174. z = random(5, 60);
  175. }
  176. delay(z);
  177. }
  178. }
  179. void check_rfid() {
  180. if (rfid100.PICC_IsNewCardPresent()) {
  181. if (rfid100.PICC_ReadCardSerial()) {
  182. loc100 = 1;
  183. }
  184. } else {
  185. loc100 = 0;
  186. }
  187. delay(20);
  188. if (rfid150.PICC_IsNewCardPresent()) {
  189. if (rfid150.PICC_ReadCardSerial()) {
  190. loc150 = 1;
  191. }
  192. } else {
  193. loc150 = 0;
  194. }
  195. delay(20);
  196. if (rfid200.PICC_IsNewCardPresent()) {
  197. if (rfid200.PICC_ReadCardSerial()) {
  198. loc200 = 1;
  199. }
  200. } else {
  201. loc200 = 0;
  202. }
  203. delay(20);
  204. if (rfid250.PICC_IsNewCardPresent()) {
  205. if (rfid250.PICC_ReadCardSerial()) {
  206. loc250 = 1;
  207. }
  208. } else {
  209. loc250 = 0;
  210. }
  211. digitalWrite(RST_PIN, LOW);
  212. delay(20);
  213. rfid100.PCD_Init();
  214. rfid150.PCD_Init();
  215. rfid200.PCD_Init();
  216. rfid250.PCD_Init();
  217. }
  218. void neo_win(int r, int g, int b) {
  219. for (w = 0; w < NUM_LEDS; w++) {
  220. pixel(r, g, b, w);
  221. delay(10);
  222. }
  223. for (w = 0; w < NUM_LEDS; w++) {
  224. pixel(0, 0, 0, w);
  225. delay(10);
  226. }
  227. }
  228. void neo_lose(int r, int g, int b) {
  229. for (w = 0; w < NUM_LEDS; w++) {
  230. pixel(r, g, b, w);
  231. delay(10);
  232. }
  233. for (w = 0; w < NUM_LEDS; w++) {
  234. pixel(0, 0, 0, w);
  235. delay(10);
  236. }
  237. }
  238. void pixel(int r, int g, int b, int p) {
  239. leds[p] = CRGB (r, g, b);
  240. FastLED.show();
  241. }

Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
Why Ayh?
Miter
Miter
@pkvi
"...may not meet professional standards."
2,364 miters
123 tenons
Subscribe
0.00394