Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Set steps_per_notch and fiddle with accelleration
Browse files Browse the repository at this point in the history
  • Loading branch information
topisani committed Jun 18, 2018
1 parent b000953 commit b42054e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 4 additions & 3 deletions arduinos/rotaries/ClickEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
// ----------------------------------------------------------------------------
// Acceleration configuration (for 1000Hz calls to ::service())
//
#define ENC_ACCEL_TOP 3072 // max. acceleration: *12 (val >> 8)
#define ENC_ACCEL_INC 25
#define ENC_ACCEL_DEC 2

constexpr unsigned ENC_ACCEL_TOP = 12 << 8;
constexpr unsigned ENC_ACCEL_INC = 25;
constexpr unsigned ENC_ACCEL_DEC = 2;

// ----------------------------------------------------------------------------

Expand Down
17 changes: 11 additions & 6 deletions arduinos/rotaries/main.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define ENC_DECODER ENC_NORMAL
#define ENC_DECODER ENC_FLAKY

#include "ClickEncoder.h"
#include "TimerOne.h"
Expand All @@ -8,6 +8,10 @@ ClickEncoder *green;
ClickEncoder *yellow;
ClickEncoder *red;

// Encoders have varying numbers of steps per physical "click".
// 4 is fairly normal.
constexpr int steps_per_notch = 4;

void print_val(ClickEncoder* enc, char name) {
int value = enc->getValue();
if (value != 0) {
Expand All @@ -29,15 +33,15 @@ void print_val(ClickEncoder* enc, char name) {
void setup() {
Serial.begin(9600);

blue = new ClickEncoder(21, 20, 19);
green = new ClickEncoder(14, 16, 15);
yellow = new ClickEncoder(3, 4, 2);
red = new ClickEncoder(9, 8, 7);
blue = new ClickEncoder(21, 20, 19, steps_per_notch);
green = new ClickEncoder(14, 16, 15, steps_per_notch);
yellow = new ClickEncoder(3, 4, 2, steps_per_notch);
red = new ClickEncoder(9, 8, 7, steps_per_notch);

Timer1.initialize(1000);
Timer1.attachInterrupt([] {
green->service();
blue->service();
green->service();
yellow->service();
red->service();
});
Expand All @@ -48,6 +52,7 @@ void loop() {
print_val(green, 'G');
print_val(yellow, 'Y');
print_val(red, 'R');
delay(10);
}

// vim: ft=cpp
Expand Down

0 comments on commit b42054e

Please sign in to comment.