![]() Encoder int SW = 19 Īlmost to the fun stuff, but we still gotta do some setup(). This number has no impact on how the encoder functions. Finally we give the encoder a starting position, basically where to start counting its positions from. I chose 500ms as it felt like a good amount. Then as I want the button to have a short and long press I set the time limit for a long press. This will take care of the button press for us making it easy to see when its press and for how long. Again this will work best if these are interrupt capable pins.Īfter we setup the encoder we setup the encoder button as a Bounce object. Then we create an Encoder object with our encoder tracking pins, in my case DT and CLK. Here just like before we tell the code what pins to use. Keypad kpd = Keypad( makeKeymap(keys), colPins, rowPins, COLS, ROWS) Ĭonst int States = Įncoder time. You can change the pin numbers at the top to what you have used. send() do release the keys they press but. With this code always remember when sending key strokes make sure that you release any keys you press. ![]() I've attached the code below and if you are interested I have an in depth walk through in the next step.įor the actual key functions I've left a few in Layout2() for you to look at. The other thing to remember is why write code many times when you can wrap it in a function and use it a bunch of times. The main thing to remember with functions is that each function should only do 1 thing. By making each section smaller, its easier to follow. Functions are useful as the make it a lot easier to keep each section of your code small. ![]() For this version I am breaking the code down into a lot more functions. The RAW pin exposes the +5v coming from the USB port. The encoder I have also needs +5v to work, so the power needs to run from the RAW pin. If you have the same encoder I do they are the DT and CLK pins. They are important as they track the movement of the encoder. On the Pro Micro attached to pin 2 and 3. The encoder will work best if the moment tracking pins connected to interrupt capable pins on the Micro. Make sure that you avoid pin 0 and 1 (RX and TX) as I think they are used to communicate with the computer tying into them might be weird. The pins aren't hugely important, as they can easily be swapped in the code later. I've attached a circuit layout that I used (or pretty close). The diodes help in case more than one switch is pressed at a time. We are basically making a grid wires with a switch and diode at each intersection. Each of the switches needs a diode and a wire.
0 Comments
Leave a Reply. |