I'm not sure if this is the right forum for this topic. Actually I built a little tank (which is working fine). But I am now trying to control an LED from my Flysky Transmitter (FS-16X) Aux Switch. I have looked at a bunch of examples but can't seem to get it to work correctly. I do see the LED on the Arduino (Uno) go from dim to brighter but not from totally off to fully on. Same goes with the LED on a breadboard. This code is something I got from Youtube and I don't have the Serial Print data in it (although I checked it on a scope and saw the PWM changing). Also this doesn't include the complete Tank Code. I would rather not do this with a library. I just need one more channel in and out (ultimately Ch5 from my receiver). I am VERY new and still extremely unsure of my coding. Thank you
int button = A4;
int led = 13;
int buttonState = 0;
void setup () {
pinMode(led, OUTPUT);
pinMode(button, INPUT);
}
void loop () {
buttonState = digitalRead(button);
if (buttonState == HIGH ) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
}
Post a wiring diagram for that button.
You use digitalWrite and that can only make a total On or a total Off.
Read the Arduino.cc/reference manual for PWM.
Is this "Flysky Transmitter (FS-16X) Aux Switch" by any chance, a common Radio Control transmitter/ receiver, in which case the output is a Pulse Length Modulation signal intended to control a servo with a pulse varying from 1 to 2 ms in length. All your present Arduino code is doing is faithfully(?) copying that to the output and feeding the LED with the same pulse train.
What you probably want to do, is to use pulseIn to measure the pulses and determine whether they last more or less than 1.5 milliseconds, and set the LED on or off accordingly. For visual effect, there is no point making that test any more often than ten times per second.
In answer to Railroader, it's a basic LED schem w/a 220 Ohm resister to gnd. And I have read through a great deal of the tutorials. That doesn't mean it's helping much. I have read through the PWM but like I said before, I am still new at coding so I have been learning by copying code and then modifying it and examining the results.
In answer to Paul__B, yes it is a Flysky and yes, I just want the LED to go on or off. But right now it's On or "Dim".
Thank you for your suggestion about pulseIn. I will try that and see if I can figure it out.
FYI - My tank has great Joystick control and 2 servo's that are being used to control a gun turret. The LED is just to imitate a laser going on & off using the Aux Switch.