Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <U8g2lib.h>
  2.  
  3. U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
  4.  
  5. void setup(void) {
  6. u8g2.begin();
  7. }
  8.  
  9. void loop(void) {
  10. u8g2.firstPage();
  11. do {
  12. u8g2.setFont(u8g2_font_ncenB14_tr);
  13. u8g2.drawStr(0,15,"Hello World!");
  14. } while ( u8g2.nextPage() );
  15. delay(1000);
  16. }
  17.  
  18.  
  19. #include <Encoder.h>
  20. #include <Encoder.h>
  21.  
  22. #include <AceButton.h>
  23. using namespace ace_button;
  24.  
  25. const int BUTTON_PIN = 2;
  26.  
  27. AceButton button(BUTTON_PIN);
  28.  
  29. void handleEvent(AceButton*, uint8_t, uint8_t);
  30.  
  31. // Change these pin numbers to the pins connected to your encoder.
  32. // Best Performance: both pins have interrupt capability
  33. // Good Performance: only the first pin has interrupt capability
  34. // Low Performance: neither pin has interrupt capability
  35. Encoder knobLeft(3, 4);
  36.  
  37.  
  38. void setup() {
  39. Serial.begin(9600);
  40. pinMode(BUTTON_PIN, INPUT);
  41. button.setEventHandler(handleEvent);
  42.  
  43.  
  44. Serial.println("TwoKnobs Encoder Test:");
  45. }
  46.  
  47. long positionLeft = -999;
  48. long positionRight = -999;
  49.  
  50. void loop() {
  51. button.check();
  52.  
  53. long newLeft, newRight;
  54. newLeft = knobLeft.read();
  55. if (newLeft != positionLeft) {
  56. Serial.print("Left = ");
  57. Serial.println(newLeft);
  58. Serial.print(digitalRead(2));
  59.  
  60. Serial.println();
  61. positionLeft = newLeft;
  62. }
  63. // if a character is sent from the serial monitor,
  64. // reset both back to zero.
  65. if (Serial.available()) {
  66. Serial.read();
  67. Serial.println("Reset both knobs to zero");
  68. knobLeft.write(0);
  69.  
  70. }
  71. }
  72.  
  73. void handleEvent(AceButton* /*button*/, uint8_t eventType,
  74. uint8_t /*buttonState*/) {
  75. switch (eventType) {
  76. case AceButton::kEventPressed:
  77. Serial.println("pressed");
  78. break;
  79. case AceButton::kEventReleased:
  80. Serial.println("released");
  81. break;
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement