Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- //Some notes:
- //This has been modified from the instructables setup
- //Ive added a Piezo Buzzer to pin 12(+) - Not required but cool
- //I changed the number of 'slots' on the 10k pot-its a little touch now but i got 2 extra gun ID's
- //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
- int piezoPin = 12;
- LiquidCrystal lcd(8,7,6,5,4,2); // setup LCD 4 bit mode
- int pulse=1; // pulse size length in microseconds
- int choice; // select laser gun model type
- int lastchoice=0; // recall last selection choice
- int fire; // trigger fire button
- void setup() {
- lcd.begin(16,2); // 16x2 LCD
- analogWrite(10,90); // foreground LCD
- analogWrite(9,150); // background LCD ~3.3 volts
- lcd.clear();
- pinMode(13, OUTPUT); // 940nM LED output (mimic 904nM laser diode)
- pinMode(11, INPUT); // setup trigger button as input
- }
- void loop() {
- choice=analogRead(0); // read laser gun model selection from 10K pot
- choice=(int)(choice/73.07); // 12 valid choices
- if (choice != lastchoice) // clear display only if it's different
- lcd.clear();
- lastchoice=choice;
- switch (choice) {
- case 0:
- lcd.setCursor(0, 0);
- lcd.print("Ultralyte Non-LR"); // 100 pulses per second
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 100, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(9999); // 10ms
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 1:
- lcd.setCursor(0, 0);
- lcd.print("Ultralyte Rev.1"); // 100pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 75, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(9999); // 10ms
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 2:
- lcd.setCursor(0, 0);
- lcd.print("Jenoptik LaserPL"); // 100pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 50, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(9999); // 10ms
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 3:
- lcd.setCursor(0, 0);
- lcd.print("Kustom Prolaser3"); // 200 pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 35, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(4999); // 5ms
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 4:
- lcd.setCursor(0, 0);
- lcd.print("Jenoptik Laveg"); // 600pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 200, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(1666);
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 5:
- lcd.setCursor(0, 0);
- lcd.print("Kustom Prolaser1"); // 380pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 1000, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(2631);
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 6:
- lcd.setCursor(0, 0);
- lcd.print("Ultralyte Rev.2"); // 125 pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 135, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(8000);
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 7:
- lcd.setCursor(0, 0);
- lcd.print("Stalker LZ-1"); // 130pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 255, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(7691);
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 8:
- lcd.setCursor(0, 0);
- lcd.print("DragonEye ECCM"); // I really hope this works
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 666, 100); //this sounds cool
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(5400.2);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(6140.3);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(6980.3);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(5550.3);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(4800.3);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(6770.3);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(5120.3);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(7150.0);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(5220.3);
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 9:
- lcd.setCursor(0, 0);
- lcd.print("Laser Atlanta"); // 238pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 750, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(4201);
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 10:
- lcd.setCursor(0, 0);
- lcd.print("Laser Atlanta"); // 238pps stealth mode
- lcd.setCursor(0,1);
- lcd.print("Stealth Mode"); // 2 pulses fire followed by 5 missing pulses Valentine One didnt alert to this one.
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 17, 100);
- lcd.setCursor(12,1);
- lcd.print("Fire");
- for (int a=1; a<=2; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(4201);
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(12603); // need 6 delays units (4201*3)
- delayMicroseconds(12603); // (4201*3)
- }
- lcd.setCursor(12,1);
- lcd.print(" ");
- }
- break;
- case 11:
- lcd.setCursor(0, 0);
- lcd.print("Kustom ProLite"); // 200 pps
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 25, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(4999); // 5ms
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 12:
- lcd.setCursor(0, 0);
- lcd.print("Truspeed"); // 4000 pps IDK if arduino refreshes fast enough - lower baud rate?
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 999, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(249); // 5ms
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- case 13:
- lcd.setCursor(0, 0);
- lcd.print("Laser Ally"); // 185 pps Maybe??
- fire=digitalRead(11);
- if (fire==0) {
- tone(piezoPin, 19.65, 100);
- lcd.setCursor(0, 1);
- lcd.print("Fire");
- for (int a=1; a<=3; a++) {
- digitalWrite(13, HIGH);
- delayMicroseconds(pulse);
- digitalWrite(13, LOW);
- delayMicroseconds(5405); // 5ms
- }
- lcd.setCursor(0, 1);
- lcd.print(" ");
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement