Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <U8g2lib.h>
- U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
- void setup(void) {
- u8g2.begin();
- }
- void loop(void) {
- u8g2.firstPage();
- do {
- u8g2.setFont(u8g2_font_ncenB14_tr);
- u8g2.drawStr(0,15,"Hello World!");
- } while ( u8g2.nextPage() );
- delay(1000);
- }
- #include <Encoder.h>
- #include <Encoder.h>
- #include <AceButton.h>
- using namespace ace_button;
- const int BUTTON_PIN = 2;
- AceButton button(BUTTON_PIN);
- void handleEvent(AceButton*, uint8_t, uint8_t);
- // Change these pin numbers to the pins connected to your encoder.
- // Best Performance: both pins have interrupt capability
- // Good Performance: only the first pin has interrupt capability
- // Low Performance: neither pin has interrupt capability
- Encoder knobLeft(3, 4);
- void setup() {
- Serial.begin(9600);
- pinMode(BUTTON_PIN, INPUT);
- button.setEventHandler(handleEvent);
- Serial.println("TwoKnobs Encoder Test:");
- }
- long positionLeft = -999;
- long positionRight = -999;
- void loop() {
- button.check();
- long newLeft, newRight;
- newLeft = knobLeft.read();
- if (newLeft != positionLeft) {
- Serial.print("Left = ");
- Serial.println(newLeft);
- Serial.print(digitalRead(2));
- Serial.println();
- positionLeft = newLeft;
- }
- // if a character is sent from the serial monitor,
- // reset both back to zero.
- if (Serial.available()) {
- Serial.read();
- Serial.println("Reset both knobs to zero");
- knobLeft.write(0);
- }
- }
- void handleEvent(AceButton* /*button*/, uint8_t eventType,
- uint8_t /*buttonState*/) {
- switch (eventType) {
- case AceButton::kEventPressed:
- Serial.println("pressed");
- break;
- case AceButton::kEventReleased:
- Serial.println("released");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement