Advertisement
pleasedontcode

"Encoder Display" rev_01

Jun 22nd, 2024
448
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 NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-22 23:28:02
  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. /****** DEFINITION OF LIBRARIES *****/
  25. #include <SimpleEncoder.h>  //http://github.com/EasyG0ing1/SimpleEncoder
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t encoder_KY_040_CLK_PIN_D2 = 2;
  33. const uint8_t encoder_KY_040_DT_PIN_D3 = 3;
  34. const uint8_t encoder_KY_040_SW_PIN_D4 = 4;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. SimpleEncoder encoder(encoder_KY_040_SW_PIN_D4, encoder_KY_040_CLK_PIN_D2, encoder_KY_040_DT_PIN_D3);
  38.  
  39. void setup(void) {
  40.     // put your setup code here, to run once:
  41.     Serial.begin(9600);
  42.     pinMode(encoder_KY_040_CLK_PIN_D2, INPUT);
  43.     pinMode(encoder_KY_040_DT_PIN_D3, INPUT);
  44.     pinMode(encoder_KY_040_SW_PIN_D4, INPUT_PULLUP);
  45. }
  46.  
  47. void loop(void) {
  48.     // put your main code here, to run repeatedly:
  49.     if (encoder.CHANGING) {
  50.         // Display the current value with 2 decimal points
  51.         float value = encoder.VALUE / 100.0;
  52.         Serial.println("Current value is: " + String(value, 2));
  53.     }
  54. }
  55.  
  56. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement