"Untitled Post" - Views: 157 · Hits: 157 - Type: Unlisted

/*
this is a phaser for fun. makes laser shooots, zappy noises, reloads needed.
really fun
tswang 8/27/2013
attiny45
reload button is the reset. 
*/
int setting = PB2; //stun or kill
int outled = PB0; //energy level (analogoutput pin)
int noisepin = PB4; //buzzer
int laser = PB1; //the laser
int trigger = PB3; //trigger

int clipsize = 6; //this is how many phases you have.
int shotaken = 0;
int noise;
int noisend;
int incrmnt;
int brightness;

void setup(){
  pinMode(setting ,INPUT);
  pinMode(outled ,OUTPUT);
  pinMode(noisepin ,OUTPUT);
  pinMode(laser ,OUTPUT);
  pinMode(trigger ,INPUT);
  
  
  
  for (int brightness = 0; brightness < 255; brightness++){
    analogWrite(outled, brightness);
    delay(10);
  }
  if (digitalRead(setting) == HIGH){
    for (int shotaken = 0; shotaken < clipsize;){
      if (digitalRead(trigger) == HIGH){
        kill();
        shotaken = shotaken + 1;
      }
    }
  }
  else{
    for (int shotaken = 0; shotaken < clipsize;){
      if (digitalRead(trigger) == HIGH){
        stun();
        shotaken = shotaken + 1;
      }
    }
  }
  for (int brightness = 255; brightness > 0; brightness--){
    analogWrite(outled, brightness);
    delay(5);
  }
  
}
void loop(){
  digitalWrite(outled, LOW);
  
  if (digitalRead(trigger) == HIGH){
    
    outofammo();
  }
  else{}

}



/*************************************************/
void stun(){
  digitalWrite(laser, HIGH);
  for (int noise = 0; noise < 1000;){  
    digitalWrite(noisepin, 1);
    delayMicroseconds(noise);
    digitalWrite(noisepin, 0);
    delayMicroseconds(noise);
    noise = noise + 1;
  }
  digitalWrite(laser, LOW);
  delay(100);
}

void kill(){
  digitalWrite(laser, HIGH);
  for (int noise = 2000; noise < 2500;){  
    digitalWrite(noisepin, 1);
    delayMicroseconds(noise);
    digitalWrite(noisepin, 0);
    delayMicroseconds(noise);
    noise = noise + 2;
  }
  digitalWrite(laser, LOW);  
  delay(100);
}

void outofammo(){
  for (int blasted = 0; blasted <5; blasted++){
    for (int ammo = 0; ammo < 100; ammo++){
      digitalWrite(noisepin,1);
      delayMicroseconds(500);
      digitalWrite(noisepin,0);
      delayMicroseconds(500);
    }
  delay(30);
  }
  delay(100);
}