This is a follow up post to Part 2 expanding on the code and adding in some of the alternative control options I mentioned.
Warning! I strongly recommend using old or second hand equipment for your experiments. I am not responsible for any damage to expensive instruments!
If you are new to Arduino, see the Getting Started pages.
Parts list
- Arduino Uno/Nano.
- DuPPa small RGB LED Ring.
- 10K potentiometer.
- KY-040 rotary encoder module.
- Bespoke hook-up wires (available from duppa.net).
- Breadboard and jumper wires.
The Circuit
This circuit shows all three control options on the same diagram, but naturally use whichever one you require. There are the following three options:
- Duppa I2C Encoder (from the previous project) on A4, A5 (SDA, SCL).
- Plain potentiometer on A0.
- Rotary encoder on D10, D11, D12.
In addition to the I2C LED Ring on A4, A5 (SDA, SCL) of course.
The Code
This uses the code from Part 2 as a starting point and adds in some additional features.
The main aim is to add additional control options and then make them selectable in code. There are several definitions at the top of the file. One of them should be uncommented to enable that control option.
//#define CC_ENCODER
#define CC_POTENTIOMETER
//#define CC_I2CENCODER
//#define CC_ENDLESSPOT
Each control method will have some associated functions, but the interface will be hidden away behind these definitions and called from the main code, something like the following.
#ifdef CC_ENCODER
#include <librarycode.h>
... control specific definitions ....
void encSetup() {
// Control specific setup code
}
void encLoop() {
// Control specific loop code
}
#else
void encSetup() {}
void encLoop() {}
No comments:
Post a Comment