Advertisement
pleasedontcode

Encoder Monitor rev_01

Oct 10th, 2024
83
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 Monitor
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-10 20:55:41
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* afficher dans le port serie un nombre evoluant */
  21.     /* grace au codeur */
  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 r_KY040_CLK_PIN_D16 = 16; // Pin for encoder A
  33. const uint8_t r_KY040_DT_PIN_D17 = 17;  // Pin for encoder B
  34. const uint8_t r_KY040_SW_PIN_D18 = 18;  // Pin for encoder button
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. // Create an instance of SimpleEncoder with the defined pins
  38. SimpleEncoder encoder(r_KY040_SW_PIN_D18, r_KY040_CLK_PIN_D16, r_KY040_DT_PIN_D17);
  39.  
  40. void setup(void)
  41. {
  42.     // Initialize serial communication at 9600 baud rate
  43.     Serial.begin(9600);
  44.  
  45.     // Set the pin modes for the encoder pins
  46.     pinMode(r_KY040_CLK_PIN_D16, INPUT);
  47.     pinMode(r_KY040_DT_PIN_D17, INPUT);
  48.     pinMode(r_KY040_SW_PIN_D18, INPUT_PULLUP);
  49. }
  50.  
  51. void loop(void)
  52. {
  53.     // Check if the encoder value is changing
  54.     if (encoder.CHANGING) {
  55.         // Print the current value to the serial monitor
  56.         Serial.println("Current value is: " + String(encoder.VALUE));
  57.     }
  58. }
  59.  
  60. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement