The lines that are added are shown in red. Let’s add the code that does the time measurement to the servo tune code of the previous video 26. If the measured time was shorter or faster than those, we know it was due to bouncing. In both cases we also do a second test, on PRESS_TIME_SHORT and on ROTARY_FAST. We read out the timer when it is released, and if ((millis() – enc_pressed_time) > PRESS_TIME_LONG) we know it was a long press, else it was short.įor the rotary encoder we start a timer at every LOW to HIGH transition and we read it out at the next LOW to HIGH transition, and if ((millis() – enc_rotated_time) > ROTARY_SLOW) we know if it was a slow rotation, else it was fast. Load up the Basic example and transfer it your Arduino board. Once installed, you’ll see under File > Examples > Encoder, which has four programs listed. ZIP Library, and add in Encoder-master.zip. ![]() On the Arduino IDE, navigate to Sketch > Include Library > Add. For the switch, we start a timer as soon as it is pressed. Download the encoder library from GitHub. To get this done we are going to use the millis() function. A long press moves the servo to its mid point. A short press toggles between the min/max setpoint angles. Distinguish between a short and a long press of the switch. ![]() We can use this to inrement the angle with small or larger steps. ![]() Distinguish between slow or fast encoder rotation.In this video the goal is to improve the Servo Tuner of video 26 with two features : Once the hardware and code is ready, just upload the code to the Arduino board and power up the Arduino Board. Remark: In case you don’t have a rotary encoder, at the end of the article you can find code to tune a servo by just using a wire, or push buttons.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |