VirtualWire library uses timer1 so pins 9 and 10 are not available for analogWrite() as they require timer1 to be set up differently.
Use 3,5,6 or 11 instead.
Thats very true, I didnt even think of it at the time I posted, I dont use CTRL-T myself as I cant see as much code per page after it has spread it out, but I should do it when I post code.
I'd suggest if you have messy code, make it a priority to tidy, even if you're not going to show it to anyone else. Just cleaning up the indentation will sometimes show you where a bug (or potential one) lies. Moreover, why make life more difficult for yourself - coding has pitfalls enough - no need to add to your problems by making it hard to read.
Lastly, I'm sure this varies by person, but the last thing I'm going to do once my code is working is to spend time prettifying it so it had better be neat already so that when I come back to it months later, I have some chance to understand it.
Not sure if this would help in your case, but you might take a look at GNU indent - it takes a gazzillion command line options, so you might be able to persuade it to format your code the way you like it indented if the IDE has mangled it for you.
Thanks wildbill, I will have a look at that when I get a minute, ( the reason I can't make a priority of tidying might be better told in a PM or barsports )
meanwhile I have another problem with my current project, with the remote controls , and see that I am also using pins 9 and 10 for inputs ( and its transmitting with VirtualWire. )
Both remotes have the same problem, where one commutating pin ( 11 ) wont go low to sample switches, and yet a previous identical version worked fine ! The only difference is that I am using the P-UP chips now ?
I am using all the available pins, so I was thinking of rather using EasyTransfer instead of VW.
I used the Softeasytransfer ( a combination of EasyTransfer and NewSoftSerial ) recently and it worked perfectly, but does that use the same timer ? I had a look at the .h file but couldn't spot it.
I suppose I could use the hardware EasyTransfer, using the TXD pin, but I am not sure how that would work when I want to test the chip in the arduino board with the USB connected.
It seems to be working fine now with SoftEasyTransfer, no problems with the analog dimming, and the remote scans all the switches OK.
I havn't tried the wireless range yet, but the last project using ET was excellent ( and at 9600 baud )
I am only using simplex for this project, it seems it will ignore any pattern of data that is not expected, and it has a checksum.....
It wasnt receiving every time, I slowed the baudrate to 4800, no different, but when I compared the Tx and Rx waveforems on the radio modules, I saw there is no preamble on the transmission, so the first couple of bits were sometimes ignored.
I solved it by transmitting twice, the first burst acting as a preamble for the data slicer in the receive module, and it seems to be working fine.
VirtualWire library uses timer1 so pins 9 and 10 are not available for analogWrite() as they require timer1 to be set up differently.
Use 3,5,6 or 11 instead.
I ended up back with VirtualWire, as the transmision was not as reliable with EasyTransfer, and I took Marks advice and cut some tacks to swap pins on the boards, so 18 hours later I have it running, though I have had to add some averaging to the light sensor to stop the dimming pulsating ( which I didnt have to do with the other version )
One day when I get some time I will look into this to understand it better.
Thanks Mark, I had used all the pins on the remote control unit, and it intermittently missed reading the thumbwheel switch connected to pin 11, ( which VW uses for rxdata - which I am not using, and dont initiate ) so I declared pin 00 ( RXD ) as the VW Rx pin, and all worked.
What a weekend ! 20 yours a day since Thursday to get this finished by last Sunday ! whoops