So if anyone could help, my two questions are;
Am I doing this right so far?
If so, how would I cycle my circle lights, and make the muzzle flash?
Code: Select all
// Using neopixel LEDs, https://github.com/adafruit/Adafruit_NeoPixel
#include <Adafruit_NeoPixel.h>
// Define all the lights (led count, pin number on board), gotta pick pins still
Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, 1);
Adafruit_NeoPixel wand = Adafruit_NeoPixel(1, 1);
Adafruit_NeoPixel muzzle = Adafruit_NeoPixel(1, 1);
Adafruit_NeoPixel circle1 = Adafruit_NeoPixel(7, 1);
Adafruit_NeoPixel circle2 = Adafruit_NeoPixel(7, 1);
Adafruit_NeoPixel circle3 = Adafruit_NeoPixel(7, 1);
Adafruit_NeoPixel circle4 = Adafruit_NeoPixel(7, 1);
const int pwrtog = 18; // pin 18 for the overall power toggle
const int trigger =20; // pin 20 for the gun trigger
const int passpwr =13; // pin 13 to pass through power
const int passtrg =2; // pin 2 for trigger passthrough
int powerstatus =0; // Are we on or off?
void setup()
{
pinMode(pwrtog,INPUT); // define input
pinMode(trigger,INPUT); // define input
pinMode(passpwr,OUTPUT); // define output
pinMode(passtrg,OUTPUT); // define output
strip.begin();
strip.show();
wand.begin();
wand.show();
muzzle.begin();
muzzle.show();
circle1.begin();
circle1.show();
circle2.begin();
circle2.show();
circle3.begin();
circle3.show();
circle4.begin();
circle4.show();
}
void loop()
{
if(digitalRead(pwrtog)==HIGH)
{
if(powerstatus==0)
{
powerstatus=1;
digitalWrite(passpwr,HIGH);
delay(500);
digitalWrite(passpwr,LOW);
strip.fill((0,0,255));
strip.show();
wand.fill((255,255,0));
wand.show();
}
// circle1-4.fill((255,0,0)) each loop?
if(digitalRead(trigger)==HIGH)
{
digitalWrite(passtrg,HIGH);
// Neopixel muzzle light, flash orange/blue ideally? muzzle.flash?
}
else
{
digitalWrite(passtrg,LOW);
// turn off muzzle light
}
}
else
{
if(powerstatus==1)
{
powerstatus=0;
digitalWrite(passpwr,HIGH);
delay(500);
digitalWrite(passpwr,LOW);
}
// Need to turn off all neopixels
}
delay(1000);
}