I have a motor driver fitted to the board, and 2 motors connected to the 2 sets of motor pins. These motors are driven in the code using low 4 : high 5 : high 6 : low 7.
I have a servo fitted to pin 0, and some led's fitted to pins 1, 2, and 3.
This all works fine, and it does what I want.
There are "vacant" digital output pins, which are numbered on the board 4, 5, 6 and 7, which are the same numbers that the motors use.
I want to fit a speaker to pin 4 (as numbered on the board) but am worried that I may blow something up, or at least I can't seem to get my head around using the same numbers for different things.
Can someone explain it to me, or at least tell me if it would be OK or not.
The motor driver is optional. If you don’t use it, digital pins 4,5,6, and 7 are available for normal use.
If you use the motor driver, pins 4,5,6, and 7 are still active, but they are also driving the motor driver. If you use them to drive something in parallel, be careful how much current you pull.
Also, if you use code on pin 4 to make a speaker go, you will wind up sending a command to the motor driver. Conversely, when you command pin 4 high to run the motor, you will be affecting the speaker output as well. You may here a click on the speaker as you transition from high to low or vice-versa.
You might have better luck sharing one of the LED pins with the speaker. If the LED is off, you can send sound to that output. The LED may even flash interestingly along with the sound signal.
Edit: Or, as I just recalled (as I saw rik’s post) you can reconfigure some of your input pins as outputs. Duh.
I think I’ve got it right, but haven’t tested it yet.
Looking up the Picaxe documentation (which I should have done in the first place) it seems that all I need to do is write high portc 1 (or low) and connect one of the LED connectors to the digital input pin 1 (freeing up one of the digital output pins). It seems that you can’t use sound on those pins, only on/off.
You’ll know when I’ve got it sussed, a new bot will go up