So, I've found the VirtualWire library, and would like to use it for some wireless modules that I have. However, I'm having an issue using the VirtualWire library and using certain pins with analogWrite. I realize these pins overlap with the VirtualWire library default pins, but I've re-assigned them, as well as tried modifying the VirtualWire.h file to change the default pins to something else. See the attached code, with this code running, the led on pin 11 works fine, but the led on pin 10 never lights up. If I comment out the line 'vw_setup(2000)' then both led's blink without issues. Using digitalWrite instead of analogWrite also works without issues.
Can anyone help me figure out what's going on?
I realize this code doesn't need the VirtualWire library, but it's just an example of my issue...
Try using the
vw_set_ptt_inverted(true);
command in your setup(). I had the same issues, but with pin 11.. but you already figured out the problem I was having.. I needed to set_ the pins.
I believe the "ptt" "Push To Talk" button is default pin 10, but even after you set it with with the vw_set, still has problems lighting up.
Hopefully the ptt_inverted should do it for you, if not, I'll copy your code and see what I get.
I'm not sure how that would matter, beings I've moved the ptt pin to a different pin.
I did however try putting 'vw_set_ptt_inverted(true);', and still no results on pin 10. This isn't a huge deal, now its more of me just getting ticked trying to figure it out
looks to me like this is caused by the fact that both analogWrite and VirtualWire both try to use Timer1. VW uses it to sample the incoming data, and analogEWrite uses it for PWM.
So is there any way to use a different timer for VirtualWire to allow use of all PWM outputs (using analogWrite)? I would like to be able to use all the PWM outputs on my arduino, or I will need to look into how to somehow get more PWM outputs for this project.
So is there any way to use a different timer for VirtualWire to allow use of all PWM outputs (using analogWrite)? I would like to be able to use all the PWM outputs on my arduino, or I will need to look into how to somehow get more PWM outputs for this project.
analogWrite uses timers timers to produce pwm. If you use vitrualwire you will lose the two PWM pins used by that timer. Changing the timer would only change the pins you would lose.