-
Notifications
You must be signed in to change notification settings - Fork 161
Description
Hello all,
i have a problem with a rotary encoder. I have try all the codes that is for encoders and always i receive the same result.
I receive the same result when rotate left or right.
I have try different pins on the Pro Micro controller.
I have try 3 types of rotary encoders.
The problem remains.
All the other parts of code works perfect.
I appreciate your help!
here is a screenshot of the problem
My Code is :
// DAW Controller MMLB Project
#include <Encoder.h>
#include <Control_Surface.h> // Include the Control Surface library
#include <AH/Hardware/Button.hpp>
#include <Arduino_Helpers.h> // Include the Arduino Helpers library
#include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp>
#include <AH/Hardware/ExtendedInputOutput/SPIShiftRegisterOut.hpp>
// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;
using namespace ExtIO;
const int speedMultiplier = 1;
// Instantiate an analog multiplexer
CD74HC4067 mux{
A0, // Analog input pin
{ 3, 4, 5, 6 } // Address pins S0, S1, S2, S3
};
// Create an array of CCPotentiometer objects that send out MIDI Control Change
// messages when you turn the potentiometers connected to the 8 inputs of the mux.
CCPotentiometer volumePotentiometers[] {
{ mux.pin(0), { MIDI_CC::General_Purpose_Controller_1, Channel_1 } },
{ mux.pin(1), { MIDI_CC::General_Purpose_Controller_1, Channel_2 } },
{ mux.pin(2), { MIDI_CC::General_Purpose_Controller_1, Channel_3 } },
{ mux.pin(3), { MIDI_CC::General_Purpose_Controller_1, Channel_4 } },
{ mux.pin(4), { MIDI_CC::General_Purpose_Controller_1, Channel_5 } },
{ mux.pin(5), { MIDI_CC::General_Purpose_Controller_1, Channel_6 } },
};
// CCBUTTONS ON MULTIPLEXER
CCButton Buttons[] {
{ mux.pin(6), { MIDI_CC::General_Purpose_Controller_2, Channel_1 } },
{ mux.pin(7), { MIDI_CC::General_Purpose_Controller_2, Channel_2 } },
{ mux.pin(8), { MIDI_CC::General_Purpose_Controller_2, Channel_3 } },
{ mux.pin(9), { MIDI_CC::General_Purpose_Controller_2, Channel_4 } },
{ mux.pin(10), { MIDI_CC::General_Purpose_Controller_2, Channel_5 } },
{ mux.pin(11), { MIDI_CC::General_Purpose_Controller_2, Channel_6 } },
{ mux.pin(12), { MIDI_CC::General_Purpose_Controller_2, Channel_7 } },
{ mux.pin(13), { MIDI_CC::General_Purpose_Controller_2, Channel_8 } },
{ mux.pin(14), { MIDI_CC::General_Purpose_Controller_2, Channel_9 } },
{ mux.pin(15), { MIDI_CC::General_Purpose_Controller_2, Channel_10 } },
};
// BUTTONS READS BUTTONS STATE
Button pushbutton1 { mux.pin(6)}; //RECORD BUTTON
Button pushbutton2 { mux.pin(7)}; //PLAY BUTTON
Button pushbutton3 { mux.pin(8)}; //STOP BUTTON
Button pushbutton13 { mux.pin(13)}; //TRACK 2 ARM ENABLE
Button pushbutton14 { mux.pin(14)}; //TRACK 2 ARM ENABLE
// Instantiate a shift register with the SPI slave select pin as latch pin, most
// significant bit first, and a total of 8 outputs.
SPIShiftRegisterOut<8> sreg {
SPI, // SPI interface to use
10, // Latch pin (ST_CP)
MSBFIRST, // Byte order
};
const pin_t ledPin0 = sreg.pin(0); // RECORD LEDS (REC & PLAY)
const pin_t ledPin1 = sreg.pin(1); // PLAY LED
const pin_t ledPin2 = sreg.pin(2); // TRACK 2 ARM ENABLE
const pin_t ledPin3 = sreg.pin(3); // TRACK 2 ARM ENABLE
CCRotaryEncoder enc {
{1, 0}, // pins
MIDI_CC::General_Purpose_Controller_5, // address
speedMultiplier, // multiplier
4, // pulses per click
};
// SETUP
void setup() {
Control_Surface.begin(); // Initialize Control Surface
sreg.begin();
pushbutton1.begin(); // RECORD BUTTON
pushbutton2.begin(); // PLAY BUTTON
pushbutton3.begin(); // STOP BUTTON
pushbutton13.begin(); // TRACK 2 ARM
pushbutton14.begin(); // TRACK 3 ARM
// You can invert the input, for use with normally closed (NC) switches:
// pushbutton.invert();
}
// LOOP
void loop() {
Control_Surface.loop(); // Update the Control Surface
static bool ledState0 = LOW; //RECORD LED
static bool ledState1 = LOW; //PLAY LED
static bool ledState2 = LOW; //TRACK 2 ENABLE LED
static bool ledState3 = LOW; //TRACK 3 ENABLE LED
// Read the digital input, debounce the signal, and check the state of
// the button:
if (pushbutton1.update() == Button::Falling) {
ledState0 = !ledState0; // Invert the state of the LED
ledState1 = !ledState1; // Invert the state of the LED
// Update the LED with the new state
digitalWrite(ledPin0, ledState0 ? HIGH : LOW);
digitalWrite(ledPin1, ledState1 ? HIGH : LOW);
}
if (pushbutton2.update() == Button::Falling) {
ledState1 = !ledState1; // Invert the state of the LED
ledState0 = !ledState0;
// Update the LED with the new state
digitalWrite(ledPin0, LOW);
digitalWrite(ledPin1, ledState1 ? HIGH : LOW);
}
if (pushbutton3.update() == Button::Falling) {
ledState0 = !ledState0; // Invert the state of the LED
ledState1 = !ledState1; // Invert the state of the LED
// Update the LED with the new state
digitalWrite(ledPin0, LOW);
digitalWrite(ledPin1, LOW);
}
if (pushbutton13.update() == Button::Falling){
ledState2 = !ledState2; // Invert the state of the LED
// Update the LED with the new state
digitalWrite(ledPin2, ledState2 ? HIGH : LOW);
}
if (pushbutton14.update() == Button::Falling){
ledState3 = !ledState3; // Invert the state of the LED
// Update the LED with the new state
digitalWrite(ledPin3, ledState3 ? HIGH : LOW);
}
}