Hello
I'm a programming beginner and I'm trying to learn from an arduino textbook and the internet.
I decided to make a stroboscopic light for the party controlled by music (microphone) with multiple effects that I switch between them using the IR controller, but I'm stuck on switching using the controller.
I found some code on google that can be used to switch the lighting effects, but the code does not work as I need it to.
I expected that when I pressed the IR_BUTTON_1 button, the flashing would turn on from the center to the edge
and when pressing the IR_BUTTON_2 button again from the edge to the center, and the LEDs will switch according to the sound intensity, but it does not work.
the effects of the session switch on but do not respond to the sound.
The microphone starts to respond to the sound and the LED flashes as soon as I hold down button 1 or 2
Thanks for all the help and advice, hopefully the solution will be simple
(sorry for the translation, google translator, CZ>EN)
With your code open in the Arduino IDE press Control-T and this will autoformat your code. That will line all the blocks up so you can easily see what's nested where. In this way you will see that the part of the code with all the if statements that react to sound are inside the if statement for there being a signal from the remote. So that code can only run if there is a signal from the remote.
Instead, the if statement that gets the command from the remote should just save the command into a variable and then the switch case part should be outside of that if statement so it runs on every loop whether there is a new signal from the remote or not.
Serial.println(soundpin); // print the ATMEGA328P pin number
should be this (twice):
Serial.println(sound); // print the value of the input
The way your code works is this:
When the A0 input is < 50, and B1 is pressed, no LEDs light
When the A0 input is < 50, and B2 is pressed, no LEDs lights
When the A0 input is 50 - 100, and B1 is pressed, the inside 1 LED lights
When the A0 input is 50 - 100, and B2 is pressed, the outside 1 LED lights (two LEDs)
When the A0 input is 100 - 150, and B1 is pressed, the inside 3 LEDs light
When the A0 input is 100 - 150, and B2 is pressed, the outside 2 LEDs lights (four LEDs)
When the A0 input is 150 - 200, and B1 is pressed, the inside 5 LEDs light
When the A0 input is 150 - 200, and B2 is pressed, the outside 3 LEDs lights (six LEDs)
When the A0 input is 200 - 250, and B1 is pressed, the inside 7 LEDs light
When the A0 input is 200 - 250, and B2 is pressed, the outside 4 LEDs lights (eight LEDs)
When the A0 input is > 250, and B1 is pressed, all 8 LEDs light
When the A0 input is > 250, and B2 is pressed, all 8 LEDs lights
BUT... the ADC on pin A0 has a range of 0 to 1023 bits... and you are only using lighting the LEDs with a 200 bit range (50 to 250)... so in this simulator, I changed your code to use the 1023 bit range split into six groups (0 - 170, 170 - 340, 340 - 510, 510 - 680, 680 - 850, 850 - 1023):
thank you for answer. Yes, I know about the range up to 1023 bits. I have set small values ββfor testing after listening to music from a mobile phone.
(I don't know if the microphone is defective or not, I expected it to be more sensitive)
anyway i tried your code and it works same as mine.
The LEDs react to music only if the button on the controller is permanently on
Okay. This can be solved by constantly monitoring the IR remote... right now, you only react to the audio when the button is pressed by using an if() condition to read the IR remote. Try taking that IR remote function out of the if() condition. Don't worry about breaking the code... you have a fallback right here.
I went through a lot of IR coding sites but couldn't find anything that worked as I needed.
I understand what you write, but I have no idea how to remove the IR from the IF() function.
I'm a beginner in coding, I'm still looking around and I would be very grateful if you could help me solve this
Look at the code. Look at the if statement. Match up the { and } after it. They surround the block of code that will be controlled by your if statement.
See in that block of code where the IR code is. Use your mouse to highlight it. On your keyboard press Control-x. That will cut out that code.
Now scroll down to right after the closing } brace on the block controlled by the if statement. Put your cursor on the line after that }. Press Control-v and it will paste the code you just cut into that place.
[quote="Delta_G, post:14, topic:1147015"]Look at the code. Look at the if statement. Match up the { and } after it. They surround the block of code that will be controlled by your if statement.
See in that block of code where the IR code is. Use your mouse to highlight it. On your keyboard press Control-x. That will cut out that code.
Now scroll down to right after the closing } brace on the block controlled by the if statement. Put your cursor on the line after that }. Press Control-v and it will paste the code you just cut into that place.
[/quote]
You still need the command to read the receiver on its own line
IrReceiver.decode(); // leave the command, without the "if()" condition
When I try to fix a program, I like to leave the old/bad lines in place (but commented-out) until I can verify the changes were good. Post your results here, good or bad.
The result will be: You must choose (one touch) 1 or 2 to tell the program to use "outside-in" LED movement or "inside-out" LED movement. The LEDs will not react until you select 1 or 2 (one touch).
only now I understood that you mean remove it from the IF conditions.
Remove the BOLD TEXT:
if( IrReceiver.decode()) { ...CODE... }
thanks guys for helping me solve my problem, I couldn't have done it without you.
It took me a long time to understand what you wanted from me, but I succeeded mainly thanks to
@ xfpd