I'm still very new at this, and haven't coded anything in years. So I have a sketch. The goal is to hook my Arduino Nano up to an arduino Audio FX Board. The FX Board has four sound files to play when I press one of four tactile buttons. That is working perfectly. When I set up my Nano, I connected D2 to the action button so that it will trigger a pattern on My leds to play with that song. I connected D4 to the fourth button directly, as well as connecting the GND from the FX board to the Nano GND on the digital pins. I will share my sketch so you can see what I'm attempting to do and tell me why its wrong. So far, the lights trigger both patterns no matter wether the music is playing and just runs the patterns in a constant loop. Can someone tell me what I am doing wrong to get this to work.
Did you try to post some code? It would also be useful to see your circuit... a schematic / good photo.
- With switches, look for a change in state rather than the switch level.
- Don't use delay( ) in your sketches as it stops normal program execution for that amount of time.
- Study what a State Machine is all about
Always attach your sketches to the thread where the question is being asked:
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 144
#define DATA_PIN 5
const int actionButton = 2;
const int PartyMode = 4;
int ButtonState1 = 0;
int ButtonState2 = 0;
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
pinMode(actionButton, INPUT);
pinMode(PartyMode, INPUT);
pinMode(DATA_PIN, OUTPUT);
} //END of setup()
void loop()
{
// First slide the led in one direction
ButtonState1 = digitalRead(actionButton);
if (ButtonState1 == HIGH)
{
for (int i = 0; i < 36; i++)
{
int j = i + 35;
int k = i + 71;
int l = i + 107;
// Set the i'th led to red
leds[i] = CRGB::Red;
leds[j] = CRGB::Red;
leds[k] = CRGB::Red;
leds[l] = CRGB::Red;
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
leds[i] = CRGB::Black;
leds[j] = CRGB::Black;
leds[k] = CRGB::Black;
leds[l] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(30);
}
// Now go in the other direction.
for (int i = 35; i >= 0; i--)
{
int j = i + 35;
int k = i + 71;
int l = i + 107;
// Set the i'th led to red
leds[i] = CRGB::White;
leds[j] = CRGB::White;
leds[k] = CRGB::White;
leds[l] = CRGB::White;
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
leds[i] = CRGB::Black;
leds[j] = CRGB::Black;
leds[k] = CRGB::Black;
leds[l] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(30);
}
}
else
{
fill_solid(leds, NUM_LEDS, CRGB::Black);
}
ButtonState2 = digitalRead(PartyMode);
if (ButtonState2 == HIGH)
{
// put your main code here, to run repeatedly:
fill_solid(leds, NUM_LEDS, CRGB(250, 125, 0));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(250, 0, 250));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(0, 0, 250));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(0, 250, 0));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(250, 125, 0));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(250, 0, 250));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(0, 0, 250));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(0, 250, 0));
FastLED.show();
delay(700);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(250, 125, 0));
FastLED.show();
delay(400);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(0, 250, 0));
FastLED.show();
delay(400);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(250, 0, 0));
FastLED.show();
delay(400);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
fill_solid(leds, NUM_LEDS, CRGB(0, 250, 0));
FastLED.show();
delay(400);
fill_solid(leds, NUM_LEDS, CRGB::Black);
delay(50);
}
else
{
fill_solid(leds, NUM_LEDS, CRGB::Black);
}
} //END of loop()
BTW
speaking of which, i know that ws2182s need the ground to be connected to both the power source and the GND on the nano, but does it matter which GND it goes to?
yes, 2812b technically
I'm trying to figure out how to upload a sketch, haven't been able to figure it out well yet. But basically, the audio FX Mini board I am using is working perfectly. I am trying to wire the ACT pin to D2 on my Nano, I am directly wiring the fourth push button I am using to D4 on the nano, with the GND pin on the Auidop FX board connected to GND on the digital switches for the Nano. Pin D5 is my output pin on the Nano for the ws2812b lights.
Please draw a diagram of what your wiring is.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.