j0h

toyGun.ino

j0h
Oct 24th, 2021
1,019
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. #ifdef __AVR__
  4.   #include <avr/power.h>
  5. #endif
  6. uint32_t prevTime;
  7. // Which pin on the Arduino is connected to the NeoPixels?
  8. // On a Trinket or Gemma we suggest changing this to 1
  9. #define PIN4          10           //data pin of pixel strip
  10. // How many NeoPixels are attached to the Arduino?
  11. #define NUMPIXELS      12
  12.  
  13. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);
  14.  
  15. const int buttonPin = 2;         // the number of the pushbutton pin
  16. const int ledPin = LED_BUILTIN;  // the number of the LED pin
  17.  
  18. int buttonState = 0;         // variable for reading the pushbutton status
  19.  
  20. //These are colours I use frequently
  21. uint32_t c=0x000000;
  22. uint32_t r=0xFF0000;
  23. uint32_t g=0x00FF00;
  24.  
  25. int counter = 8;
  26.  
  27. void reload(){
  28.   Serial.println("I'm Realoading");
  29.   for(int i = 0; i<=NUMPIXELS; i++){
  30.     pixels.setPixelColor(i, r);
  31.     delay(99);
  32.     pixels.show();
  33.     }
  34.   counter = 8;
  35.   delay(1300);
  36.   }
  37.  
  38. void unload(){
  39.   //pew pew!
  40.     digitalWrite(ledPin, HIGH);
  41.     Serial.print("Fire! ");
  42.     counter = counter - 1 ;
  43.     pixels.setPixelColor(counter, c);
  44.     pixels.show();
  45.     Serial.println( counter);
  46.     delay(300);
  47.     digitalWrite(ledPin, LOW);
  48.   }
  49. void initz(){
  50.   //initialize: start out with a full clip
  51.     //I learned you cant call a function "init()"
  52.     for(int i = 0; i<=NUMPIXELS; i++){
  53.     pixels.setPixelColor(i, g);
  54.     delay(88);
  55.     pixels.show();
  56.     }
  57.   counter = 8;
  58.   }
  59.  
  60.  
  61. void setup() {
  62. Serial.begin(9600);
  63.   pinMode(ledPin, OUTPUT);
  64.   pinMode(buttonPin, INPUT);
  65.   pinMode(PIN4,OUTPUT );
  66.   pixels.begin();  
  67.   pixels.setBrightness(55);
  68.   initz();
  69. }
  70.  
  71. void loop() {
  72.  
  73.   buttonState = digitalRead(buttonPin);
  74.   if (buttonState == HIGH) {
  75.  unload();
  76.   } else {
  77.     // turn LED off:
  78.     digitalWrite(ledPin, LOW);
  79.   }
  80.   if (counter<=0){
  81.     reload();
  82.     }
  83. }
RAW Paste Data