Hi I am having some difficulty in coding and even wiring this simple project. I have all my wiring except I want to use an arcade happ style button as the timers reset button. and I want to use the 2812 to light up one after the other while time elapses. I also have a buzzer go off when the time is done. I only have basic coding skills and this is being a challenge I tried using millis but could not reset the lights and start again.
also i dont know how to wire up the reset button which is a Happ with a com1 and a NC 2 and a NO 3. so i am not sure the best way to do it. I am using FastLed for the ws2812b and want to keep the code functional any help with direction on this one would be appreciated. there are 7 Leds in the strand i made. thanks for any help on this one.
and if the timer can be adjusted with a potentiometer that would be great lowest like 1 minute on high like 5 minutes would make the project more multi dimensional.
I got it all wired up with my test strand lighting and my analog potentiometer wired right and for now I am using a gnd 220ohm switch to D7 and my pezio is on pwm 5 each component works with tester code but I need huge direction on this for writing the code. 8^)
Here is a fritz of the wiring. The ws2812b is not the same model as I am using a GeekCreit and it has 3 in 3 out. One ground one power and a data line. They are daisy chained together. They work I have tested them. any guidance on what the best way to program this easily would be great.
I know it does nothing but thats all I got so far, not sure how to keep track of time and light up the led's one at a time at a adjustable by the potentiometer delay rate. that then can be reset and started over by pressing the button.
Any direction on what way to do that would be good.
Ok I updated the code it lights up at a interval controlled by the knob however I got no reset button code. Any one got any ideas I added a clear function call reset(); but now need to get the button going to activate the reset code and star it again.
You say your button has 3 pins but your schematic shows 4 so I'm not really sure which is correct. What you want to typically do is connect the common to your input pin and connect the normally open (NO) to ground. You don't need the resistor. You also have to declare the input pin to use the internal pullup resistor (which you did!)
Then, when the button is not being pressed, it is not connected to anything so the internal pullup pulls the pin HIGH. When the button is pressed, it is shorted to ground and reads LOW.
blh64:
You say your button has 3 pins but your schematic shows 4 so I'm not really sure which is correct. What you want to typically do is connect the common to your input pin and connect the normally open (NO) to ground. You don't need the resistor. You also have to declare the input pin to use the internal pullup resistor (which you did!)
Then, when the button is not being pressed, it is not connected to anything so the internal pullup pulls the pin HIGH. When the button is pressed, it is shorted to ground and reads LOW.
do you have any ideas how to get the code to run the "void stages1, stages2, etc.. functions" while monitoring the button to activate a reset function. that would be most helpful.
Is delTime going to stay at zero? Then remove all the lines that say delay(delTime);
If it's going to be bigger than about 50 in the future, then you need to do this a totally different way, which involves removing all the lines that say delay(delTime);
Go to your Arduino IDE and open up the Examples. Look at the first Digital example: BlinkWithoutDelay. Make that work with the built-in LED. Make it work with one of your WS218 strips. Note how it uses the variable ledState to remember where it is up to in the cycle? You need to do something similar except you will have more states than just on and off.
MorganS:
Is delTime going to stay at zero? Then remove all the lines that say delay(delTime);
If it's going to be bigger than about 50 in the future, then you need to do this a totally different way, which involves removing all the lines that say delay(delTime);
Go to your Arduino IDE and open up the Examples. Look at the first Digital example: BlinkWithoutDelay. Make that work with the built-in LED. Make it work with one of your WS218 strips. Note how it uses the variable ledState to remember where it is up to in the cycle? You need to do something similar except you will have more states than just on and off.
Hey man thanks for your interest. delTime is adjustable with the potentiometer and changes the speed at which the strip lights up changing the "time" it takes for the players turn to run out and the buzzer goes off. I am open for accomplishing this any way.
I will look into that example and see if it helps.
Ok thanks for the tip, I have made some progress using some code another member wrote for me on another project and the blink with out delay example. If you could review the code and suggest how I can make the buzzer sound that would be great and I need to find a way to change the interval with a potentiometer. The button kind of works some of the time.
#include <FastLED.h>
#include <JC_Button.h> // https://github.com/JChristensen/JC_Button
#define PIN_STRIP1 3
#define COLOR_ORDER RGB
#define LED_TYPE WS2812
#define NUM_LEDS 7
uint8_t max_bright = 255;
struct CRGB leds1[NUM_LEDS];
int ledColor1[7] = {CRGB::Blue,CRGB::Green,CRGB::Blue,CRGB::Blue,CRGB::Green,CRGB::Blue,CRGB::Blue}; // Color for strip 1
const byte PIN_BUTTON_RESET (7);
Button BUTTON_RESET(PIN_BUTTON_RESET);
byte NumStrip1 = 0;
const int potPin = A0;
long interval = 2000;//analogRead(potPin) * 10;
unsigned long previousMillis = 0;
void setup() {
// put your setup code here, to run once:
LEDS.addLeds<LED_TYPE, PIN_STRIP1, COLOR_ORDER>(leds1, NUM_LEDS);
FastLED.setBrightness(max_bright);
FastLED.clear();
FastLED.show();
BUTTON_RESET.begin();
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
BUTTON_RESET.read(); // read Reset BUTTON
if (BUTTON_RESET.wasPressed()) ResetStrips ();
else ChangeStrip1();
}
}
void ChangeStrip1 () {
leds1[NumStrip1] = ledColor1[NumStrip1];
NumStrip1 = min(NumStrip1 + 1, NUM_LEDS - 1);
FastLED.show();
}
void ResetStrips () {
FastLED.clear();
NumStrip1 = 0;
FastLED.show();
}
// save the last time you blinked the LED
previousMillis = currentMillis;
BUTTON_RESET.read(); // read Reset BUTTON
if (BUTTON_RESET.wasPressed()) ResetStrips ();
else ChangeStrip1();
}
So when does it check the button? Only once per interval. Remove that from the interval and check it every loop.
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
ChangeStrip1();
}
BUTTON_RESET.read(); // read Reset BUTTON
if (BUTTON_RESET.wasPressed()) {
ResetStrips ();
previousMillis = currentMillis;
}
I figured it out. Now one last piece of the puzzle is to use a analogRead to change the interval.
Any idea on how to make the interval adjustable with the pot, I am really scratching my head on that. I tried passing it the value and multiplying it by 10 but it just makes the strip instantly light up.
I am using a 10k pot and serial monitor is registering a value from 0 to 1023
When you put analogRead() in your loop you may want to use something like this that is found on the Arduino Reference page. It is called the map() function.
cyclegadget:
When you put analogRead() in your loop you may want to use something like this that is found on the Arduino Reference page. It is called the map() function.