Hey all, I posted this on the Adafruit forum as well but if there's anyone here who'd be able to help me out, that'd be super awesome <3 I realise this isn't about a specific movie prop but the code would be so useful for my other projects as well if I/ or anyone else wanted to add sound and light to those too! If you want to follow my build, I'm on instagram too @raekalia.props - if you can't help then at least give me a follow so you can watch me struggle and feel that sweet sweet schadenfreude
------
I'm very new to microcontrollers and circuitry in general, this is actually my first project and I've made a lot of progress from the 0% knowledge I started out with 2 weeks ago but I'm a little stuck now...I'm making a weird alien box for university which has reed (magnetic) switch activated lights and sounds. I've followed this guide to a T pretty much in terms of circuitry - https://learn.adafruit.com/ray-gun-blaster
However I'm using 4 switches instead of 1, 2 Neopixel rings rather than 1, stereo rather than mono and I haven't added the laser. When I finished the circuit and input the code, I realised a bit too late that of course the code would only apply to 1 switch instead of the 4 that I have; I'm not yet adept enough to start changing the code more than just the colours and speed of the LEDs so I don't know how to accomodate this code to my circuit. Would anyone be able to help me make this code for 4 switches as opposed to 1 so that I'd be able to play around with different light settings for each switch after? I'm not really sure how easy/difficult this is so please let me know.
// Original Kaleidoscope eyes code from Phillip Burgess.
// Modified to play spinning animation when push button is set to low
//Written by Philip Burgess for Adafruit Industries.
//Adafruit invests time and resources providing this open source code,
//please support Adafruit and open-source hardware by purchasing products
//from Adafruit!
//BSD license, all text above must be included in any redistribution.
#include <Adafruit_NeoPixel.h>
#define PIN 0 //NeoPixel Pin
#define FIREPIN 2 // Fire button
int buttonState = 0; //Default button state
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(12, PIN);
uint8_t offset = 0; // Position of spinny eyes
uint32_t color = 0x00ff5a; // HEX color here
uint32_t prevTime;
void setup() {
pixels.begin();
prevTime = millis();
pinMode(FIREPIN, INPUT_PULLUP); //Button enabler
}
void loop() {
uint8_t i;
uint32_t t;
buttonState = digitalRead(FIREPIN); //Trigger button state
if (buttonState == LOW) { // If button pressed
for(i=0; i<16; i++) { //Run the animation
uint32_t c = 0; //Blank color
if(((offset + i) & 7) < 2) c = color; // 4 pixels on...
pixels.setPixelColor(i, c); //Set the color of pixels
}
pixels.show();
offset++;
}
t = millis();
if((t - prevTime) > 10) { // Every 10th of a second...
for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
prevTime = t;
}
else {
pixels.setPixelColor(i, 0,0,0); //Button not pressed, turn off pixels
pixels.show(); //Show no pixels
delay(25); //duration of spinniness
}
}
------
I'm very new to microcontrollers and circuitry in general, this is actually my first project and I've made a lot of progress from the 0% knowledge I started out with 2 weeks ago but I'm a little stuck now...I'm making a weird alien box for university which has reed (magnetic) switch activated lights and sounds. I've followed this guide to a T pretty much in terms of circuitry - https://learn.adafruit.com/ray-gun-blaster
However I'm using 4 switches instead of 1, 2 Neopixel rings rather than 1, stereo rather than mono and I haven't added the laser. When I finished the circuit and input the code, I realised a bit too late that of course the code would only apply to 1 switch instead of the 4 that I have; I'm not yet adept enough to start changing the code more than just the colours and speed of the LEDs so I don't know how to accomodate this code to my circuit. Would anyone be able to help me make this code for 4 switches as opposed to 1 so that I'd be able to play around with different light settings for each switch after? I'm not really sure how easy/difficult this is so please let me know.
// Original Kaleidoscope eyes code from Phillip Burgess.
// Modified to play spinning animation when push button is set to low
//Written by Philip Burgess for Adafruit Industries.
//Adafruit invests time and resources providing this open source code,
//please support Adafruit and open-source hardware by purchasing products
//from Adafruit!
//BSD license, all text above must be included in any redistribution.
#include <Adafruit_NeoPixel.h>
#define PIN 0 //NeoPixel Pin
#define FIREPIN 2 // Fire button
int buttonState = 0; //Default button state
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(12, PIN);
uint8_t offset = 0; // Position of spinny eyes
uint32_t color = 0x00ff5a; // HEX color here
uint32_t prevTime;
void setup() {
pixels.begin();
prevTime = millis();
pinMode(FIREPIN, INPUT_PULLUP); //Button enabler
}
void loop() {
uint8_t i;
uint32_t t;
buttonState = digitalRead(FIREPIN); //Trigger button state
if (buttonState == LOW) { // If button pressed
for(i=0; i<16; i++) { //Run the animation
uint32_t c = 0; //Blank color
if(((offset + i) & 7) < 2) c = color; // 4 pixels on...
pixels.setPixelColor(i, c); //Set the color of pixels
}
pixels.show();
offset++;
}
t = millis();
if((t - prevTime) > 10) { // Every 10th of a second...
for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
prevTime = t;
}
else {
pixels.setPixelColor(i, 0,0,0); //Button not pressed, turn off pixels
pixels.show(); //Show no pixels
delay(25); //duration of spinniness
}
}
Last edited by a moderator: