Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.23 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. //Some notes:
  4.  
  5. //This has been modified from the instructables setup
  6. //Ive added a Piezo Buzzer to pin 12(+) - Not required but cool
  7. //I changed the number of 'slots' on the 10k pot-its a little touch now but i got 2 extra gun ID's
  8. //Its setup for a LCD Display. It seems to work fine without it attatched though. I could remove the code in the Future if unwatned/downsizing
  9.  
  10. int piezoPin = 12;
  11.  
  12. LiquidCrystal lcd(8,7,6,5,4,2); // setup LCD 4 bit mode
  13. int pulse=1; // pulse size length in microseconds
  14. int choice; // select laser gun model type
  15. int lastchoice=0; // recall last selection choice
  16. int fire; // trigger fire button
  17.  
  18.  
  19. void setup() {
  20. lcd.begin(16,2); // 16x2 LCD
  21. analogWrite(10,90); // foreground LCD
  22. analogWrite(9,150); // background LCD ~3.3 volts
  23. lcd.clear();
  24. pinMode(13, OUTPUT); // 940nM LED output (mimic 904nM laser diode)
  25. pinMode(11, INPUT); // setup trigger button as input
  26.  
  27. }
  28.  
  29. void loop() {
  30. choice=analogRead(0); // read laser gun model selection from 10K pot
  31. choice=(int)(choice/73.07); // 12 valid choices
  32.  
  33. if (choice != lastchoice) // clear display only if it's different
  34. lcd.clear();
  35. lastchoice=choice;
  36.  
  37. switch (choice) {
  38. case 0:
  39. lcd.setCursor(0, 0);
  40. lcd.print("Ultralyte Non-LR"); // 100 pulses per second
  41. fire=digitalRead(11);
  42. if (fire==0) {
  43. tone(piezoPin, 100, 100);
  44. lcd.setCursor(0, 1);
  45. lcd.print("Fire");
  46. for (int a=1; a<=3; a++) {
  47. digitalWrite(13, HIGH);
  48. delayMicroseconds(pulse);
  49. digitalWrite(13, LOW);
  50. delayMicroseconds(9999); // 10ms
  51. }
  52. lcd.setCursor(0, 1);
  53. lcd.print(" ");
  54. }
  55. break;
  56. case 1:
  57. lcd.setCursor(0, 0);
  58. lcd.print("Ultralyte Rev.1"); // 100pps
  59. fire=digitalRead(11);
  60. if (fire==0) {
  61. tone(piezoPin, 75, 100);
  62. lcd.setCursor(0, 1);
  63. lcd.print("Fire");
  64. for (int a=1; a<=3; a++) {
  65. digitalWrite(13, HIGH);
  66. delayMicroseconds(pulse);
  67. digitalWrite(13, LOW);
  68. delayMicroseconds(9999); // 10ms
  69. }
  70. lcd.setCursor(0, 1);
  71. lcd.print(" ");
  72. }
  73. break;
  74. case 2:
  75. lcd.setCursor(0, 0);
  76. lcd.print("Jenoptik LaserPL"); // 100pps
  77. fire=digitalRead(11);
  78. if (fire==0) {
  79. tone(piezoPin, 50, 100);
  80. lcd.setCursor(0, 1);
  81. lcd.print("Fire");
  82. for (int a=1; a<=3; a++) {
  83. digitalWrite(13, HIGH);
  84. delayMicroseconds(pulse);
  85. digitalWrite(13, LOW);
  86. delayMicroseconds(9999); // 10ms
  87. }
  88. lcd.setCursor(0, 1);
  89. lcd.print(" ");
  90. }
  91. break;
  92. case 3:
  93. lcd.setCursor(0, 0);
  94. lcd.print("Kustom Prolaser3"); // 200 pps
  95. fire=digitalRead(11);
  96. if (fire==0) {
  97. tone(piezoPin, 35, 100);
  98. lcd.setCursor(0, 1);
  99. lcd.print("Fire");
  100. for (int a=1; a<=3; a++) {
  101. digitalWrite(13, HIGH);
  102. delayMicroseconds(pulse);
  103. digitalWrite(13, LOW);
  104. delayMicroseconds(4999); // 5ms
  105. }
  106. lcd.setCursor(0, 1);
  107. lcd.print(" ");
  108. }
  109. break;
  110. case 4:
  111. lcd.setCursor(0, 0);
  112. lcd.print("Jenoptik Laveg"); // 600pps
  113. fire=digitalRead(11);
  114. if (fire==0) {
  115. tone(piezoPin, 200, 100);
  116. lcd.setCursor(0, 1);
  117. lcd.print("Fire");
  118. for (int a=1; a<=3; a++) {
  119. digitalWrite(13, HIGH);
  120. delayMicroseconds(pulse);
  121. digitalWrite(13, LOW);
  122. delayMicroseconds(1666);
  123. }
  124. lcd.setCursor(0, 1);
  125. lcd.print(" ");
  126. }
  127. break;
  128. case 5:
  129. lcd.setCursor(0, 0);
  130. lcd.print("Kustom Prolaser1"); // 380pps
  131. fire=digitalRead(11);
  132. if (fire==0) {
  133. tone(piezoPin, 1000, 100);
  134. lcd.setCursor(0, 1);
  135. lcd.print("Fire");
  136. for (int a=1; a<=3; a++) {
  137. digitalWrite(13, HIGH);
  138. delayMicroseconds(pulse);
  139. digitalWrite(13, LOW);
  140. delayMicroseconds(2631);
  141. }
  142. lcd.setCursor(0, 1);
  143. lcd.print(" ");
  144. }
  145. break;
  146. case 6:
  147. lcd.setCursor(0, 0);
  148. lcd.print("Ultralyte Rev.2"); // 125 pps
  149. fire=digitalRead(11);
  150. if (fire==0) {
  151. tone(piezoPin, 135, 100);
  152. lcd.setCursor(0, 1);
  153. lcd.print("Fire");
  154. for (int a=1; a<=3; a++) {
  155. digitalWrite(13, HIGH);
  156. delayMicroseconds(pulse);
  157. digitalWrite(13, LOW);
  158. delayMicroseconds(8000);
  159. }
  160. lcd.setCursor(0, 1);
  161. lcd.print(" ");
  162. }
  163. break;
  164. case 7:
  165. lcd.setCursor(0, 0);
  166. lcd.print("Stalker LZ-1"); // 130pps
  167. fire=digitalRead(11);
  168. if (fire==0) {
  169. tone(piezoPin, 255, 100);
  170. lcd.setCursor(0, 1);
  171. lcd.print("Fire");
  172. for (int a=1; a<=3; a++) {
  173. digitalWrite(13, HIGH);
  174. delayMicroseconds(pulse);
  175. digitalWrite(13, LOW);
  176. delayMicroseconds(7691);
  177. }
  178. lcd.setCursor(0, 1);
  179. lcd.print(" ");
  180. }
  181. break;
  182. case 8:
  183. lcd.setCursor(0, 0);
  184. lcd.print("DragonEye ECCM"); // I really hope this works
  185. fire=digitalRead(11);
  186. if (fire==0) {
  187. tone(piezoPin, 666, 100); //this sounds cool
  188. lcd.setCursor(0, 1);
  189. lcd.print("Fire");
  190. for (int a=1; a<=3; a++) {
  191. digitalWrite(13, HIGH);
  192. delayMicroseconds(pulse);
  193. digitalWrite(13, LOW);
  194. delayMicroseconds(5400.2);
  195.  
  196. digitalWrite(13, HIGH);
  197. delayMicroseconds(pulse);
  198. digitalWrite(13, LOW);
  199. delayMicroseconds(6140.3);
  200.  
  201. digitalWrite(13, HIGH);
  202. delayMicroseconds(pulse);
  203. digitalWrite(13, LOW);
  204. delayMicroseconds(6980.3);
  205.  
  206. digitalWrite(13, HIGH);
  207. delayMicroseconds(pulse);
  208. digitalWrite(13, LOW);
  209. delayMicroseconds(5550.3);
  210.  
  211. digitalWrite(13, HIGH);
  212. delayMicroseconds(pulse);
  213. digitalWrite(13, LOW);
  214. delayMicroseconds(4800.3);
  215.  
  216. digitalWrite(13, HIGH);
  217. delayMicroseconds(pulse);
  218. digitalWrite(13, LOW);
  219. delayMicroseconds(6770.3);
  220.  
  221. digitalWrite(13, HIGH);
  222. delayMicroseconds(pulse);
  223. digitalWrite(13, LOW);
  224. delayMicroseconds(5120.3);
  225.  
  226. digitalWrite(13, HIGH);
  227. delayMicroseconds(pulse);
  228. digitalWrite(13, LOW);
  229. delayMicroseconds(7150.0);
  230.  
  231. digitalWrite(13, HIGH);
  232. delayMicroseconds(pulse);
  233. digitalWrite(13, LOW);
  234. delayMicroseconds(5220.3);
  235. }
  236. lcd.setCursor(0, 1);
  237. lcd.print(" ");
  238. }
  239. break;
  240. case 9:
  241. lcd.setCursor(0, 0);
  242. lcd.print("Laser Atlanta"); // 238pps
  243. fire=digitalRead(11);
  244. if (fire==0) {
  245. tone(piezoPin, 750, 100);
  246. lcd.setCursor(0, 1);
  247. lcd.print("Fire");
  248. for (int a=1; a<=3; a++) {
  249. digitalWrite(13, HIGH);
  250. delayMicroseconds(pulse);
  251. digitalWrite(13, LOW);
  252. delayMicroseconds(4201);
  253. }
  254. lcd.setCursor(0, 1);
  255. lcd.print(" ");
  256. }
  257. break;
  258. case 10:
  259. lcd.setCursor(0, 0);
  260. lcd.print("Laser Atlanta"); // 238pps stealth mode
  261. lcd.setCursor(0,1);
  262. lcd.print("Stealth Mode"); // 2 pulses fire followed by 5 missing pulses Valentine One didnt alert to this one.
  263. fire=digitalRead(11);
  264. if (fire==0) {
  265. tone(piezoPin, 17, 100);
  266. lcd.setCursor(12,1);
  267. lcd.print("Fire");
  268. for (int a=1; a<=2; a++) {
  269. digitalWrite(13, HIGH);
  270. delayMicroseconds(pulse);
  271. digitalWrite(13, LOW);
  272. delayMicroseconds(4201);
  273. digitalWrite(13, HIGH);
  274.  
  275. delayMicroseconds(pulse);
  276. digitalWrite(13, LOW);
  277. delayMicroseconds(12603); // need 6 delays units (4201*3)
  278. delayMicroseconds(12603); // (4201*3)
  279. }
  280. lcd.setCursor(12,1);
  281. lcd.print(" ");
  282. }
  283. break;
  284. case 11:
  285. lcd.setCursor(0, 0);
  286. lcd.print("Kustom ProLite"); // 200 pps
  287. fire=digitalRead(11);
  288. if (fire==0) {
  289. tone(piezoPin, 25, 100);
  290. lcd.setCursor(0, 1);
  291. lcd.print("Fire");
  292. for (int a=1; a<=3; a++) {
  293. digitalWrite(13, HIGH);
  294. delayMicroseconds(pulse);
  295. digitalWrite(13, LOW);
  296. delayMicroseconds(4999); // 5ms
  297. }
  298. lcd.setCursor(0, 1);
  299. lcd.print(" ");
  300. }
  301. break;
  302. case 12:
  303. lcd.setCursor(0, 0);
  304. lcd.print("Truspeed"); // 4000 pps IDK if arduino refreshes fast enough - lower baud rate?
  305. fire=digitalRead(11);
  306. if (fire==0) {
  307. tone(piezoPin, 999, 100);
  308. lcd.setCursor(0, 1);
  309. lcd.print("Fire");
  310. for (int a=1; a<=3; a++) {
  311. digitalWrite(13, HIGH);
  312. delayMicroseconds(pulse);
  313. digitalWrite(13, LOW);
  314. delayMicroseconds(249); // 5ms
  315. }
  316. lcd.setCursor(0, 1);
  317. lcd.print(" ");
  318. }
  319. break;
  320. case 13:
  321. lcd.setCursor(0, 0);
  322. lcd.print("Laser Ally"); // 185 pps Maybe??
  323. fire=digitalRead(11);
  324. if (fire==0) {
  325. tone(piezoPin, 19.65, 100);
  326. lcd.setCursor(0, 1);
  327. lcd.print("Fire");
  328. for (int a=1; a<=3; a++) {
  329. digitalWrite(13, HIGH);
  330. delayMicroseconds(pulse);
  331. digitalWrite(13, LOW);
  332. delayMicroseconds(5405); // 5ms
  333. }
  334. lcd.setCursor(0, 1);
  335. lcd.print(" ");
  336. }
  337. break;
  338.  
  339.  
  340. }
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement