Hi everybody. I'm new to the ardunio platform, so i'm trying to teach my self how to program this thing to vary the pwm using 5 inputs (A0 though A4). that will be later . right now i am attepting varying the pwm just using A0 and A1. reading the serial port i just get the thrid setting i've established. any suggestions? Here's my code so far
if it makes any sence, i am clamping the pins high or low to test my theroy. i don't care what comes out of the pwm right now. i am just trying to get the pwm to follow my movements. i am using an uno board, pin 13 does work as a pwm output, i already proved that to myself with a previous program i wrote about 2 hours ago.
A PWM function, when used in context of an Arduino, implies using the core library function called analogWrite() ( analogWrite() - Arduino Reference ) Which is only supported on certain pins depending on processor model as the library utilizes internal timers that only attach to certain output pins.
On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 through 13. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.
Your using the term PWM in it's broader form. Any output pin can be used for "bit banging" a pwm output signal.
i can re-assign the pwm output pin later. i changed the commas in the if statemens to &&. the pwm still stays at a given rate. that is not what i am trying to accomplish right now. i am trying to get the pwm to change according to the inputs i am using.
i am trying to get the pwm to change according to the inputs i am using.
At the bottom of your code, you are using Serial.print() to output values. Use that same technique to output the values read from the analog pins, and in each if block. It will quickly become obvious where your problem(s) are.
When people suggest code changes, it's nice to say whether you changed your code, or not. If not, explain why not. If you did, post the new code, so we can see whether there are other software problems.
i am sorry if there is any confusion as to what i am trying to do here. all i want is for the arduino to pick one pwm setting per program rotation. now having said that.
the bottom of the code uses serial print to display A0, A1 , and PWM. i stated i did change the code, on lines 35, 39, and 43 i changed the , to &&. the rest of the code is exactly the same.
keyVal1 is A0
keyVal2 is A1
here's the end lines:
if(keyVal1>500 && keyVal2<500);
{
PWM=255;
}
if(keyVal1<500 && keyVal2>500);
{
PWM=255/1.1;
}
if(keyVal1<500 && keyVal2<500);
{
PWM=255/1.2;
}
Your last posted code still had semicolons on the 'if' statements. (see reply #2)
Remove them.
You've also still got your floating-point divide, which you'll have to change.
Please use the # (code) icon on the editor's toolbar when posting code.
by clamping the inputs i mean i am applying either +5v or grnd to the pin directly. this is still just a test. on the values i get: PWM- 221 A0 if tied to grnd 0 if tied to 3.3vdc 692 A1 if tied to grnd 0 if tied to +5vdc 1023. like i said i am trying to get the ardunio to pick one instance or another. here's the code redone:
no i do not get a negetive number. that was just to say PWM dash interger. i have yet to attempt getting a negitive number on the board. btw i started using this thing on monday
again, i am varying the inputs to try to have the program select one of 3 outputs.
I guess I'm missing something. Given the values read from analog pins 0 and 1, which appear to sometimes be floating, you are getting a correct value for PWM. So, what seems to be the problem?
okay let's look at this at a diffrent angle: if i had an on-on switch (2 position) and told the arduino to change the pwm according to the switch setting. how would i program that into the program, using the analog inputs.