MCPcopy Create free account
hub / github.com/PaulStoffregen/Encoder / Encoder

Function Encoder

Encoder.h:79–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77{
78public:
79 Encoder(uint8_t pin1, uint8_t pin2) {
80 #ifdef INPUT_PULLUP
81 pinMode(pin1, INPUT_PULLUP);
82 pinMode(pin2, INPUT_PULLUP);
83 #else
84 pinMode(pin1, INPUT);
85 digitalWrite(pin1, HIGH);
86 pinMode(pin2, INPUT);
87 digitalWrite(pin2, HIGH);
88 #endif
89 encoder.pin1_register = PIN_TO_BASEREG(pin1);
90 encoder.pin1_bitmask = PIN_TO_BITMASK(pin1);
91 encoder.pin2_register = PIN_TO_BASEREG(pin2);
92 encoder.pin2_bitmask = PIN_TO_BITMASK(pin2);
93 encoder.position = 0;
94 // allow time for a passive R-C filter to charge
95 // through the pullup resistors, before reading
96 // the initial state
97 delayMicroseconds(2000);
98 uint8_t s = 0;
99 if (DIRECT_PIN_READ(encoder.pin1_register, encoder.pin1_bitmask)) s |= 1;
100 if (DIRECT_PIN_READ(encoder.pin2_register, encoder.pin2_bitmask)) s |= 2;
101 encoder.state = s;
102#ifdef ENCODER_USE_INTERRUPTS
103 interrupts_in_use = attach_interrupt(pin1, &encoder);
104 interrupts_in_use += attach_interrupt(pin2, &encoder);
105#endif
106 //update_finishup(); // to force linker to include the code (does not work)
107 }
108
109
110#ifdef ENCODER_USE_INTERRUPTS

Callers

nothing calls this directly

Calls 1

attach_interruptFunction · 0.85

Tested by

no test coverage detected