Module Encodeur rotatif compatible Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
// Custom Mouse Wheel As PocketNC Jog Wheel // https://www.allwinedesigns.com/blog/pocketnc-jog-wheel #include "Mouse.h" int pinA = 7; int pinB = 6; volatile int previous = 0; volatile int counter = 0; void setup() { pinMode(pinA, INPUT_PULLUP); pinMode(pinB, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(pinA), changed, CHANGE); attachInterrupt(digitalPinToInterrupt(pinB), changed, CHANGE); Mouse.begin(); } void changed() { int A = digitalRead(pinA); int B = digitalRead(pinB); int current = (A << 1) | B; int combined = (previous << 2) | current; if(combined == 0b0010 || combined == 0b1011 || combined == 0b1101 || combined == 0b0100) { counter++; } if(combined == 0b0001 || combined == 0b0111 || combined == 0b1110 || combined == 0b1000) { counter--; } previous = current; } void loop(){ if(counter >= 4) { Mouse.move(0,0,1); counter -= 4; } else if(counter <= -4) { Mouse.move(0,0,-1); counter += 4; } } |
Volume up/down
Nécessite la librairie: https://github.com/NicoHood/HID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
// https://github.com/AllwineDesigns/PocketNCJogWheel/blob/master/arduino/VolumeControl/VolumeControl.ino #include "HID-Project.h" int pinA = 2; int pinB = 3; volatile int previous = 0; volatile int counter = 0; void setup() { pinMode(pinA, INPUT_PULLUP); pinMode(pinB, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(pinA), changed, CHANGE); attachInterrupt(digitalPinToInterrupt(pinB), changed, CHANGE); Keyboard.begin(); } void changed() { int A = digitalRead(pinA); int B = digitalRead(pinB); int current = (A << 1) | B; int combined = (previous << 2) | current; if(combined == 0b0010 || combined == 0b1011 || combined == 0b1101 || combined == 0b0100) { counter++; } if(combined == 0b0001 || combined == 0b0111 || combined == 0b1110 || combined == 0b1000) { counter--; } previous = current; } void loop(){ if(counter >= 4) { Keyboard.write(KEY_VOLUME_UP); counter -= 4; } else if(counter <= -4) { Keyboard.write(KEY_VOLUME_DOWN); counter += 4; } } |
Up/Down key
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
// https://github.com/AllwineDesigns/PocketNCJogWheel/blob/master/arduino/UpDownKeys/UpDownKeys.ino #include "HID-Project.h" int pinA = 2; int pinB = 3; volatile int previous = 0; volatile int counter = 0; void setup() { pinMode(pinA, INPUT_PULLUP); pinMode(pinB, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(pinA), changed, CHANGE); attachInterrupt(digitalPinToInterrupt(pinB), changed, CHANGE); Keyboard.begin(); } void changed() { int A = digitalRead(pinA); int B = digitalRead(pinB); int current = (A << 1) | B; int combined = (previous << 2) | current; if(combined == 0b0010 || combined == 0b1011 || combined == 0b1101 || combined == 0b0100) { counter++; } if(combined == 0b0001 || combined == 0b0111 || combined == 0b1110 || combined == 0b1000) { counter--; } previous = current; } void loop(){ if(counter >= 4) { Keyboard.write(KEY_UP); counter -= 4; } else if(counter <= -4) { Keyboard.write(KEY_DOWN); counter += 4; } } |