Advertisement
pleasedontcode

"Encoder Display" rev_02

Jun 22nd, 2024
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Encoder Display"
  13.     - Source Code compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-22 23:29:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* displays number from a dial that shows 100 */
  21.     /* graduation in a 360 rotation in 2 decimal points */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <SimpleEncoder.h>  //http://github.com/EasyG0ing1/SimpleEncoder
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t encoder_KY_040_CLK_PIN_D2 = 2;
  34. const uint8_t encoder_KY_040_DT_PIN_D3 = 3;
  35. const uint8_t encoder_KY_040_SW_PIN_D4 = 4;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. SimpleEncoder encoder(encoder_KY_040_SW_PIN_D4, encoder_KY_040_CLK_PIN_D2, encoder_KY_040_DT_PIN_D3);
  39.  
  40. void setup(void) {
  41.     // put your setup code here, to run once:
  42.     Serial.begin(9600);
  43.     pinMode(encoder_KY_040_CLK_PIN_D2, INPUT);
  44.     pinMode(encoder_KY_040_DT_PIN_D3, INPUT);
  45.     pinMode(encoder_KY_040_SW_PIN_D4, INPUT_PULLUP);
  46. }
  47.  
  48. void loop(void) {
  49.     // put your main code here, to run repeatedly:
  50.     if (encoder.CHANGING) {
  51.         // Display the current value with 2 decimal points
  52.         float value = encoder.VALUE / 100.0;
  53.         Serial.println("Current value is: " + String(value, 2));
  54.     }
  55. }
  56.  
  57. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement