Summary of libraries we're using, and what timers they use:
Servo.h: timers 1, 3, 4, and 5
Tone libraries:
- tone (built-in): timer 2. (Apparently uses more timers than that if you try to play more than one tone at the same time.) Any pins you want, though beware of PWM conflicts.
- NewTone: timer 1. Any pins you want, though beware of PWM conflicts.
- toneAC: timer 1. Pins 11 and 12 only, requires specialized wiring. Let's you control volume, which the other libraries don't.
- toneAC2:
timer 2. Any pins you want, though beware of PWM conflicts. Requires
specialized wiring. Gets you twice the volume, though can't control it.
We likely don't ever need to use this one.
NewPing (for ultrasonic sensor):
- timer 2 by default, but our
version (on Moodle site) sets the TIMER_ENABLED variable to false, which
makes it use no timers at all. It disables the capability for the
function ping_timer doesn't work, but you only need that if you want to
try to do fancy multitasking-like behavior automatically. We can code
around that in other ways.
Timers and PWM pins: (see RedBack documentation and this summary as well)
- Timer 0: Pins 4 and 13
- Timer 1: Pins 11 and 12
- Timer 2: Pins 9 and10
- Timer 3: Pins 2, 3, 5
- Timer 4: Pins 6, 7, 8
- Timer 5: Pins 44, 45, 46
Why does this matter? Two reasons:
- You can't use two libraries at the same time that use the same timer
- If
you use a library with a timer that is associated with a set of pins
for PWM (e.g., Servo.h with timer 5, which is associated with pins 44-46
for PWM), beware of using those pins for a different device that
requires PWM, such as a dimmable LED. analogWrite uses PWM, and will
only work on a pin associated with a timer.