pwm switch

Hi to all,
I am sad to say a code copy and paste er. I fly quad copters and only know the basics about programming arduino. I am an IF and THEN programmer with a jump to label type of programmer to say.
I want to program LED's and purchased some neopixels. There is some code out there I may be able to use but I want to do this, I want to use a pwm channel on my remote to switch different colors and patterns using a pwm signal. my taranis has a 6 position switch I want to use for selection of patterns. Basicly IF pwm signal is 1000 TO 1200 THEN flash lights this way . IF pwm signal is 1201 to 1300 THEN make all lights orange. IF pwm is 1301 to 1400 then turn all lights to chase .ect. ect. ect.
Maybe even assighn another channel for speed of a chase . how would I do such a thing in arduino? is there maybe a book for beginers to get me there. I am building a UFO quad copter 4 foot round and this is the biggest part of the build. I did flash my mega and start a sample program but that's it, I guess I am a flasher looking into crossing over to get arduino to work for me with the neopixels. any help is always greatly appreciated.

My code would basically come from the neopixel strand test if that helps. I plan on using that as a starting point and ad on from there.


this isnt beginner stuff… (not advanced…but not beginner either… I guess medium experience)

The Neopixels require specific timing to run properly… (this is all handled for you in the library, so no worries)…

however… this does leave the processor pretty busy running/driving the Neopixel strip(s)…

In order to leave/make ‘room’ for the processor to check for other things (like a button press)… you’ll need to code your neopixel patterns/animations in a certain way…

(I think there is an advanced Neopixel tutorial on the Adafruit site that outlines this as well)

So basically instead of having the Neopixel animation/pattern be stuck in an updating ‘loop’…

your pattern/animation code would only update the pattern to the next ‘step’ (ie: light up the next led in sequence for example)… then go back to the MAIN loop and check any button input… if not… returns to the pattern function increments/update the next step…

goes back to MAIN loop to check for button input…etc…etc

…rinse & repeat

PWM values are 0 to 255.

PWM values are 0 to 255.

good point.

I was thinking his 'pwm' values were coming from his 'remote' thingy.

I kind of want to shy away from a mechanical switch. Looking for a sample of code that would switch a certain loop a cording to pwm input on a pin within a specified range. It's done for flight modes in multiwii but there is to much code for me to go through to find an example of it. As for how hard can it be? It took me 1 year to learn how to program ladder logic in plc's and to program a fanuc robot including the hmi on the teach pendant in html code. It was a lot to learn but my head didn't blow up. I think I can figure this out with some help and direction. I will probably have a lot of questions though. Oh and the fanuc robot I wired, configured io welded frames, the whole work cell by myself so I don't lack in the electrical side either.

I was thinking his 'pwm' values were coming from his 'remote' thingy.

And that would indeed appear to be the case - standard RC servo control signals with which he wishes to implement a "pseudo-servo" which translates to colour commands.

I believe the "PulseIn" library call is the basic - but imperfect - way of implementing this.

I was thinking his 'pwm' values were coming from his 'remote' thingy.

Paul is right. RC servo signal commands are in uS, not pwm values. The values the OP cited are consistent with RC servo signal commands (Servo Library) so they SHOULD NOT be called "PWM",
(even though they are a specific subset of pwm) , they should be called SERVO commands because they did NOT come from any arduino PWM pin. They came from some source of RC servo signals. (whatever that might be)

So in other words I am an idiot that doesn't know the difference between pwm and a servo signal. I asked for help that I posted in the arduino forum for project guidance. I looked up pulsein library and sure it measures time between pulses but not really what I was looking for. I take it I have to figure this out for myself. Sorry I botherd you with such a simple question. What forum answers the simple questions to beginners with a goal to accomplish?

Don't overreact ok. Nobody called you an idiot.
Your post title is "PWM SWITCH" but actually it's a servo signal ( PPM, not PWM) . I didn't see the word "servo" in your original post. You're a newbie calling a servo signal PWM on an arduino forum where "PWM" typically refers to analogWrite signals. As an electronics expert with 35 years experience, it is my JOB to inform you that your post title and terminology is incorrect and I am not supposed to worry about how you react to that information , which is all it is. You can thank me for informing you or tell me to go to hell. Frankly, I don't give a damn. If you want to keep calling it PWM I can't stop you. If you want to argue that it is a form of PWM , completely unlike the analogWrite PWM, that's your prerogative. I should tell you that when you post on the forum , anything and everything you say that is incorrect will be corrected by someone. We are nit going to apologize for correcting you because the whole world expects us to. That's exactly WHY people come here. They want to know the truth, the whole truth, and nothing but the truth, so help me ...
Just say " Thanks for the heads up on the nomenclature " and don't get all bent out of shape.
We are not going to think " I better not correct him because he might fly off the handle.. ". We are supposed to educate you. That's our job.
Welcome to the forum.

FREQ = 50 Hz
Resolution +/- 1 mS
Minimum pulse width: 1 mS
Maximum pulse width : 2 mS
Period: 20 ms
Max Duty Cycle : 10% (2 mS of a 20mS period)

FREQ: 480 Hz or 980 Hz
Resoloution 0 to 100% (8 bits)
Minimum pulse width: 0 mS
Maximum pulse width : 2.0833 mS (480 Hz) 1.0416 mS (980 Hz)
Period: 2.0833 mS (480 Hz) 1.0416 mS (980 Hz)
Max Duty Cycle : 100%

Thanks for the heads up on the nomenclature. And your saying I have to post a new thread and be very specific on what I want to do, what my hardware is and brush up on the arduino terms in the libraries.
What book would you recommend for a beginner to read so I can learn to complete my task? There are no arduino classes anywhere near me so I have to learn it on my own.

I didn't say any such thing. I didn't say you had to do anything. I simlly said it's our job to correct anything you say here that is incorrect. We cannot other readers to believe it is ok to do the same thing. If we don't correct it then others will thing that is the right terminology. As far as what recommend for your arduino research , I can say that K havs had a great deal of success by simply putting the word "arduino" at the beginning of all Google searches When necessary ,I include the word "schematic" or " example" or "code".

Let me give you an example.
Suppose a newbie posts saying he wants to "modulate" his RC servo.
Would we then repeat his mistake saying "you can modulate your servo by etc etc"
No , of course not. We would reply:

"Servos use a special subset of PWM called PPM using the Servo Library. The "PWM" pins on the arduino are not used for servo control and would not work if you tried it.

We don't say 'pwm the servo'. We simply say 'drive the servo' to avoid readers confusing this with the pins labeled PWM on the arduino"

If someone posted asking how to "modulate a motor using a digital pin" we would reply:

"The PWM pins on the arduino can be used to PWM the motor (Google search "PWM") using the analogWrite() function."

Every time a newbie uses the wrong terminology he/she will be corrected many times as necessary.

We're like CSI MIAMI . We never close.

I wasn't being sarcastic, sorry if taken. Thought we were past that. I wasn't asking someone to wright my code for me, I want to know how to program a lot of neopixel leds for my quad copter ufo I am building. I build quads for fun and fly them fpv. I have naze32 and apm all the bells and whistles quads with osd fpv. The apms all loiter. I am building a quad with 15" propellers with a ufo body. The light effects will make or break it. So that's as much as I know about arduino. Config.h. flash.
I will try in the led forum that I should have asked about it in. What book is the best one? There are many out there. I got mega boards to program but I would like to go small as possible with lots of memory I guess.

Your in Project Guidance.
You don't need Project Guidance because you already have a Design Criteria that defines the parameters of your project. You need Programming help. That's where you should post. Your post title sucks. Change it to "Using CASE function and PulseIn() to read RC Transmitter switch positions"

or you could Google those.

You can keep your post title if you think it is more effective than what I suggested. I’m sorry you are sensitive to my comment about your choice of post title. I could just have easily said, " I don’t think that is a good post title because an RC SERVO signal is called a “servo signal” , not a “pwm signal” here on the forum where arduinos are sold with pins labeled “PWM” that have nothing to do with your post.
I stand by my statement that you should use “servo signal” instead of “pwm”, for the reasons just given.
Being upset because I corrected your terminology or criticized your post title is counter productive.
The post you linked should be useful for obtaining the duration but I still feel you would be better off posting in Programming for “Using CASE & PulseIn to read RC Transmitter Switch Positioins” and then
for the 400 outputs you might post on General Electronics for the hardware part and in Programming for the NeoPixel programming help. If you just take a moment to research “arduino CASE function” and
“arduino PulseIn” , I think you will find that using them is very straightforward. Have a cup of coffee and then Google those terms. The 400 outputs is probably going to lead toward using a 74Ls595 or possibly
an I/O Expander. I think CASE would work better for you than your usual “IF , THEN” but I’m a H/W person so I’m no expert on programming. Your project is very complex. I think you should try to remain calm. You’ll get more work done.

My only suggestion is that you create a formal Design Criteria itemizing the tasks in your project and attach the Word document to your posts. Also you should link the Neopixels so members can research those.

I went with neopixel because I don't want hardware, and wanted to move to the next level and program the 400 leds adresses in loops, 6 of them. Like you I am a hardware guy but this was the most logical way to make up a cool light show the neighbors will be talking about for years. I live in farm country. Believe me looking into the project I would love to just build a big quad but that wouldn't be unique to me. I will look up what you recommend because who else recomended anything and you do know how this stuf works way more than me. I would like to intigrate some arduino stuff in my automation stuff I build but really don't know squat about it, YET, hence back to the book, what one is the good one? I know how to flash a firmware, rom, bootloader but need to know code. There are no arduino classes probably in my whole state.

Your first priority should be the Design Criteria.

Also, I should point out that it is human nature to seek the most interesting post so if you want to attract more help you have to "SELL" you project by embellishing your post with photos, a running SITREP report (Milspeak for SITUATION REPORT), parts lists, and of course the all important DESIGN CRITERIA.

What a hassle. I am newbie as well and understand what you are after. I cant recommend a book but I would take some of those keywords they have mentioned and start searching at youtube. Something i find very useful is to just download the videos at keepvid dot com and then use VLC media player and i play them back at 2x the speed until i run across what I am looking for. You have persevered with your current projects and I'm sure once you find that magic word it will open many doors to what you are after. Best of luck.

There ate no shortcuts.
Do you think engineers design that way ?

I would like to intigrate some arduino stuff in my automation stuff I build but really don't know squat about it, YET, hence back to the book, what one is the good one? I know how to flash a firmware, rom, bootloader but need to know code. There are no arduino classes probably in my whole state.

I think you are overestimating the difficulty of using an arduino. I only started in Nov of 2013. I had no programming experience before that other than a couple of classes in school. Since then I have built hundreds of arduino based projects. Here is one of them.

Instead of assuming it is going to be all uphill why don't you assume it's going to be all downhill and post for one task at a time.
I already told you where to look for the "Servo Switch" program. You already have the post you found that can read the pulse duration. Just use that to find out your switch pulse widths (unless you already have that. If you do, you should have posted the list for all 6 switches on your original post. Once you have the list of pulse widths, use the CASE statement. Post in the Programming Topic with the post title I recommended. You should have the working code within 24 hours. If you want people to read your post, make it look organized. Create an outline.

Or if you don't want to do any work and you want to take the shortcut route you can follow the other posters suggestion to not try to figure anything out yourself and just try to find someone else's work online and copy that. As far as that goes, your "Servo Switch" sketch should have been covered in some past posts since that sounds like something many people have had to do. Try searching on Google and then post the link to your Google search in your post. OP's are always claiming they spent days Googling and found nothing, but they NEVER post the link to their Google search and ask the question "What am I doing wrong with this search ? Why can't I find anything ?"
I suggested putting the word "arduino" at the beginning of your searches. I can see you still haven't posted on the Programming Topic for the "Servo switch". Does that mean you are figuring it out your self or you already found the solution ?

Right now I am playing with strand test to see how it works, I plan to modify it and reverse engineer it and create a few loops. I am starting out with a 30 per meter neopixel so as not to overcook my brain. After the reverse engineering I should almost understand a few more things. Then I plan to figure out the next step, try switching loops . I could use button and get a switch and activate it by using a servo plugged into my receiver. Or I could figure out my original plan and measure pulse time and set loops to run accordingly with a lot less extra weight and wires and a feeling that I accomplished something. I guess you can say I am figuring out stepping through loops right now. Plus I am not de bugging a robot cell right now and need to feel I did something. Not giving up if that's what your asking. As I said this is an important task to accomplish for my project. Problem is summer will fly by fast so I got to get cracking