Тёмный

The correct way to use buttons with FastLed library, Arduino and WS2812 NEOPIXEL 

Ionut Fedaceag
Подписаться 2,5 тыс.
Просмотров 21 тыс.
50% 1

NO SOFTWARE DEBOUNCING FOR BUTTONS AND NO DELAYS !!! for a smooth animation ...
1. SOFTWARE DEBOUNCING VS HARDWARE DEBOUNCING ...
2. HOW NOT TO KILL YOUR ARDUINO ...
3. ALWAYS USE A COMMON GROUND WHEN USING MULTIPLE POWER SUPPLIES...
FastLED is a fast, efficient, easy-to-use Arduino library for controlling addressable LED strips, in this case WS2812B NEOPIXEL ( more info can be found here fastled.io/ ).
The sketch and the basic schematic can be downloaded here: drive.google.com/file/d/1OrjC...
Paypal donations: paypal.me/ThinkSmallBuildBig
Patreon donations: / thinksmallbuildbig
Link's Romania
ARDUINO UNO R3 ATmega328p - l.profitshare.ro/l/7066416
Arduino Nano v3 - l.profitshare.ro/l/7066421
ATTINY85 - l.profitshare.ro/l/7066418
Atmega328P-PU - l.profitshare.ro/l/7066420
WS2812B 144 LEDs/m - ardushop.ro/ro/electronica/33...
WS2812b 60 Leds/m - www.iluminat-ieftin.ro/1224/B...
LM2596 DC-DC Step Down Regulator Input 3.2V-40V Output 1.25V-35V Adjustable Buck Converter - l.profitshare.ro/l/7066446
MP1584EN DC-DC Step Down 3A Adjustable Buck Converter - l.profitshare.ro/l/7066447

Наука

Опубликовано:

 

2 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 72   
@trueindia808
@trueindia808 3 года назад
Thanks Sir, Very nice clip & step by step detail
@JuanFunQi
@JuanFunQi 3 года назад
Thanks as always I learn a ton of something new more more more
@Marc_Miller
@Marc_Miller 4 года назад
Hello Ionut. Great tutorial! Really good to show others how to hardware debounce and avoid using delay. One things I will point out-- the number at the end of the fadeToBlackBy line is not a time unit (not per second), but rather a fade percentage. So in your case, using 5, means fade by 5/256th, or fade by about 1.9% each time the line is run. Using 128 would be a 50% fade each time it is called.
@IonutFedaceag
@IonutFedaceag 3 года назад
Hi and thanks! :) I admit that i never read the manual for fadeToBlackBy , i presumed that is a time unit, judging by the result that is produced while changing it's value. Thanks for pointing it out! :)
@user-uj2kj9zm3b
@user-uj2kj9zm3b 3 года назад
Hi I wander haw to use the signal from the car blinkers to the buttons
@xcruell
@xcruell 3 года назад
Thank you :)
@PESCADATRETA
@PESCADATRETA 3 года назад
GOOD VIDEO mate you deserve more views and subs! thank you for this awsome explanation! increase the font size for the videos ;)
@octogames6823
@octogames6823 2 года назад
Thank you so much! I just completed this project with a 24 rgb led ring pcb. Super silly question. How do I adjust the code to keep all LED's on with no animations?
@mannersmakethman3668
@mannersmakethman3668 Год назад
You are my hero!!!!!!!!
@IonutFedaceag
@IonutFedaceag 11 месяцев назад
🤣
@martinkuliza
@martinkuliza 10 месяцев назад
And then a hero comes along With the programming strength to carry on and you cast your fears aside cause you know you can survive......... ohhhhhhhhhh so when you feel like hope is gone Come to you tube when you're strong and you'll finally see the truth THAT THE PROGRAMMING SKILLS LIES IN YOU LOL
@wawanirianto2130
@wawanirianto2130 3 года назад
Do you have sketch arduino nano for 2 Way ledstrip?
@user-zh4hq3lo5f
@user-zh4hq3lo5f 5 месяцев назад
Your project is great. It is exactly what I want to do. The only difference is that I do not want the strip to sweep. I want to tun the whole strip red,green,blue solid respectively. switching between each color with button 1. How do you modify your code to do that?
@fabiolus2007
@fabiolus2007 3 года назад
Thank You sir! Seem to work with INPUT_PULLUP eliminating resistor.
@stefint4316
@stefint4316 4 года назад
Hello, can you also provide link to the on/off, momentary and toggle switches you are using in your demonstrations? Thank you
@IonutFedaceag
@IonutFedaceag 4 года назад
Hi. Do you mean the link to the sketch used in this clip? Because the link is in the description! With pleasure! ;)
@Electronieks
@Electronieks 3 года назад
no working link for the sketch?
@johnvargo8050
@johnvargo8050 3 года назад
This is great information thank you. Will there be a bounce problem if powering the Arduino from the 5v power supply instead of USB?
@martinkuliza
@martinkuliza 10 месяцев назад
That is completely irrelevant BOUNCE has nothing to do with power Bounce relates to the imperfection of a button's contact point and the imperfect way in which a human would press it. In a perfect world pressing a button would result in one contact of the button , Nothing more , nothing less. in the real world, a person pushes a button, they may slip, they may have water on their hands on sweat or they didn't realize they need to push harder or whatever, they have shaky hands perhaps in any case, it results in multiple contacts This has nothing to do with how you power it when using a button ASSUME THERE WILL ALWAYS BE A BOUNCE ISSUE
@scottiusnevious5143
@scottiusnevious5143 4 года назад
So for my final project i should just solder power to the boards 5v and not from something else?
@IonutFedaceag
@IonutFedaceag 4 года назад
Everything in this example works on 5v ! But i don't think that i quit understand your question...
@steveanimatrix3887
@steveanimatrix3887 4 года назад
Good video, but it would really help if you increased your font size in your IDE when making videos so it's easier for us to read.
@IonutFedaceag
@IonutFedaceag 4 года назад
Thanks! No problem, in future videos i will make it so. ;)
@jommeldockx1793
@jommeldockx1793 4 года назад
Can I know what's the best LED you've used so far?
@IonutFedaceag
@IonutFedaceag 4 года назад
Well with the buying of the ws2812b led it's a real lottery, because officially only one company is producing this type of leds and that is worldsemi ... but in real life you really don't know, because they are not marked. Until 2015 i had real problem with finding good quality leds and the majority of leds lasted about nine to twelve months, but from the mid 2015 i settled to buy the leds from only two online shops and that was a good choice, because now i don't have any problems with the leds, the only factor's that i need to get right is the cooling and a stable power supply and the leds will last. The oldest strip has almost four years and it's still working... www.iluminat-ieftin.ro/1224/Banda-LED-RGB-PIXEL-2812-60-led-m-18W ardushop.ro/ro/electronica/331-banda-leduri-rgb-neopixels-ws2812b.html?search_query=ws2812&results=4
@alfredomolina2697
@alfredomolina2697 Год назад
Hello, where did you learn to programming neopixel ws2812 LEDs, I would like learn it, it's awesome that you make
@IonutFedaceag
@IonutFedaceag 11 месяцев назад
If go thru FastLed documentation fastled.io/docs/ and you know how to program in arduino, everything will be verry clear...
@ronitsharma7936
@ronitsharma7936 2 года назад
I was trying to implement your code into a strip of 10 less but I get an error message for "fadeToBlackBy( leds[0], COUNT, 5);" , and the error message being "cannot convert 'CRGB' to 'CRGB*' for argument '1' to 'void fadeToBlackBy(CRGB*, uint16_t, uint8_t)".
@IonutFedaceag
@IonutFedaceag 2 года назад
I think you accidentally changed something that you shouldn't have... Download the sketch again, modify only the number of leds and test again.
@samad419
@samad419 3 года назад
copied the code exact and it wont change color :( Correction! after enough understanding and watching you're video a couple times I've managed to not just get it working but control multiple LED strips with one button for each one! Thank you!
@bkmo9859
@bkmo9859 4 года назад
Can you be so kind as provide a code example for triggering the hazard light section of a sketch using the original directional controls of a motorcycle? Such as a switch with left-off-right orientation. Where as one of a right-off-left-off switch selection within 3 or 4 seconds would trigger the hazard lights. Thank you. I already have a hazard controller using attiny85 triggered by a separate switch. I want it to trigger by original switch with a right left button push.
@IonutFedaceag
@IonutFedaceag 4 года назад
I think that i understand what you need, but i need more details. Please explain with more details how the original controls work ... a clip will be nice ... and il see how i can help you.
@bkmo9859
@bkmo9859 4 года назад
@@IonutFedaceag There are no hazard lights on the motorcycle originally. just directionals. I have added hazard lights myself by adding 12v output of my own controller to the left and right positive feeds of the directional lights. I dont want to use an external switch to turn them on. I would like the arduino sketch to detect a quick right then left switching of the directional controls to start the hazard light sequence that feed flashing 12v via 2 mosfets to the directional lights. What I need is help with the code to detect the right-off-left-off switch inputs and run the loop for the hazards. The original control is a switch that latches the load of the flasher relay to the directional light. left-off-right if pushed right it stays on until you push center to release the switch, same for left. I want to go right-left-center to start the flasher code outputting to the mosfets.
@IonutFedaceag
@IonutFedaceag 4 года назад
Did you run the original signal switch thru the attiny85? Because you will need them to go thru the attiny85 to be able to detect the combination of buttons and the delay for detecting the hazard combination will also be added to both turn signals. I will think of a sollution in the comming days and i will get back to you. EDIT: Please send me a link for the original switch or at least a picture of it.
@bkmo9859
@bkmo9859 4 года назад
@@IonutFedaceag it is like the one here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Ob4JWFQ6aTc.html it is connected to the directionals only. I will add button inputs via opto-isolators to my attiny85 flasher module
@IonutFedaceag
@IonutFedaceag 4 года назад
If the switch latches in position, i think this should work... drive.google.com/file/d/1ZpcZ6TPaM5N17WZgP-P-ADVf2XVaeEqF/view?usp=sharing Am i right?
@justinhawley7783
@justinhawley7783 4 года назад
Great video! It's amazing how hard it is to find in depth learning for using tactile switches with Fastled. Do you know if there is an easy way to declare the button at the beginning of an existing sketch to switch between multiple functions? For example, say I wanted to have blue change to red indefinitely, then I push the button and it changes to orange to yellow, then push it again and get a twinkle pattern, etc? I know Tweak4all has one sketch like this, but I would like to be able to make my own basic versions with a button. Sorry if this doesn't make sense, I'm not a coder but I want to learn this stuff.
@IonutFedaceag
@IonutFedaceag 3 года назад
Thanks! I didn't understand to well your question, but anything can be done... of course you will need to make some modification to your existing sketch to be able to take in account the changes made by the new code...
@Outlabyrinth
@Outlabyrinth 4 года назад
thanks ! really helpful could you create a fonction when 2 button are pressed ? for exemple : if button 1 and 2 = 1 that willl run a fonction lets say changing colors could you help me to write the code ? please !!
@IonutFedaceag
@IonutFedaceag 4 года назад
With pleasure ;) Well, with the example from this clip i think you could achieve what you want... but yes, i can help you if you can't. Try it yourself and if you can't achieve it, i will make a clip on how you can use two buttons and trigger at list six functions with them.
@Outlabyrinth
@Outlabyrinth 4 года назад
@@IonutFedaceag thanks a lot you are very kind to the community !
@IonutFedaceag
@IonutFedaceag 4 года назад
​@@Outlabyrinth With pleasure... ;)
@stevecummins324
@stevecummins324 4 года назад
Easy software debouncing without delay loop.... In main loop update previous switch state, and read current switch state. If they aren't same that is potentially bouncing... Set a countdown timer to a high value. If countdown timer greater than 1...decrement timer by 1 Continue with rest of main loop Only consider a read button state valid if countdown value=0
@IonutFedaceag
@IonutFedaceag 4 года назад
The great thing of software is that it's always better way of doing things. Yes, that can be another way of doing it, but a timer means a float and a float takes a lot o memory... so doing it in hardware, at least for me it's cheaper (in terms of memory)...
@stevecummins324
@stevecummins324 4 года назад
@@IonutFedaceag Rather than a float you mean an unsigned long? 4bytes.
@IonutFedaceag
@IonutFedaceag 4 года назад
Yes, sorry... unsigned long... last night i had a few drinks before responding to comments! :D :) Let's say for ATtiny85, 4 bytes of memory for one variable/button is to much, from my point of view. Like i said in most of my videos and in the description of this channel, i'm not a full time programmer, so I will confuse them from time to time, so sorry for that... :) ;)
@nico4597
@nico4597 4 года назад
Hey, how do i pass the currentcolor value through for(int l = 0; l < NUM_LEDS_PER_STRIP; l++){ leds[l]=CRGB::currentColor; FastLED.show(); CRGB doesnt take these kinds of values Awesome tutorial btw
@IonutFedaceag
@IonutFedaceag 4 года назад
Well, if you use CRGB struct (hex color type), you need to make a list of the colors that you need and run thru them. This is a color picker www.w3schools.com/colors/colors_picker.asp and lets say that this is the hex for red color #ff0000 and you will use it like this 0xff0000 . The variable type for holding the currentColor hex value can be an unsigned long . Or you can change to CHSV struct and use it like this: for(int l = 0; l < NUM_LEDS_PER_STRIP; l++){ leds[l]=CHSV(hue,saturation,brightness); FastLED.show(); } github.com/FastLED/FastLED/wiki/FastLED-HSV-Colors Thanks.
@Elysuim
@Elysuim 2 года назад
Excellent video, I'm currently searching for how to make 2 buttons produce 2 colour modes, Button 1 = Solid RED, Button 2 = fast chasing rainbow effect. Also wonder would an Opto Isolator reduce "Bounce" or are they so fast that Hardware or Software delay will still be neccessary?
@IonutFedaceag
@IonutFedaceag 2 года назад
Glad you like it. Even if you use an optocoupler, you still have to switch it on with a button, which will still produce "Bounce" and yes, the optocoupler is fast... From my experience, the condenser and resistor are the best choice when you really need to reduce "bounce", but for most cases, software debouncing is enough. 😉
@arifrismawanto1198
@arifrismawanto1198 4 года назад
Coding tanpa tombol ada ndak
@IonutFedaceag
@IonutFedaceag 4 года назад
???
@arifrismawanto1198
@arifrismawanto1198 4 года назад
@@IonutFedaceag sketch without buttons there or not
@IonutFedaceag
@IonutFedaceag 4 года назад
If you want the sketch without buttons, just replace this line in the sketch leds[0][pos] += CHSV( currentColor, 255, currentBrt); with leds[0][pos] += CHSV( 0, 255, 255); and ignor the rest (buttons and other code)... To set your color and intensity, just change the three values parentheses with values from 0 to 255 ... the order is (color, saturation, brightness).
@pablowojat4517
@pablowojat4517 3 года назад
no compila
@CallousCoder
@CallousCoder 2 года назад
I am not a fan of your else if statements. A good state engine can just use if statements and a state procedure, will return the next state. A while loop with an array of function pointers where the input is the state is cleanest. Although I myself only do that if we have more than 10 or so states. Because I’m also not a fan of long if blocks.
@IonutFedaceag
@IonutFedaceag 11 месяцев назад
Yes i feel you, it's hard to keep track of all the states and it gets messy quickly when using a lot of if statements, but this is the method i control the best and since i don't code for living, the time limited for learning... 🙃
@vipalsharma4120
@vipalsharma4120 Год назад
Hopeless
@IonutFedaceag
@IonutFedaceag 11 месяцев назад
Why is that ?
@wawanirianto2130
@wawanirianto2130 3 года назад
Do you have sketch arduino nano for 2 Way ledstrip?
Далее
HOW TO USE WS2812B NEOPIXELS WITH FASTLED ON ARDUINO
24:32
NeoPixel 105 - millis() Timing
11:10
Просмотров 1,4 тыс.
would you eat this? #shorts
00:23
Просмотров 2 млн
Brawl Stars Animation: PAINT BRAWL STARTS NOW!
00:52
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
NeoPixel 211 button functions
23:41
Просмотров 1,8 тыс.
CrowdStrike IT Outage Explained by a Windows Developer
13:40
Sensors - which one to use
17:06
Просмотров 1,3 млн
Controlling WS2812B RGB LEDs
6:34
Просмотров 44 тыс.
Telefonu Parçaladım!😱
0:16
Просмотров 30 млн