Go Down

Topic: Flickering Potentiometer (Read 1 time) previous topic - next topic

ciabio

I don't have much time right now, I'll try to integrate it later.

Analog reading is done in src/MIDI_Outputs/Analog.cpp.

For now, you can use the Analog::map function.

You could write out a different function for all inputs explicitly, but it's better to use lambda functions.
If you want to do it automatically, you have to use the latest code on the lambda branch that supports capturing lambda expressions, and the following code:

Code:
#include <MIDI_Controller.h> // Include the library
#include "HystFilter.h"

Analog potentiometers[] = {
  {A0, MIDI_CC::Channel_Volume, 1},
  {A1, MIDI_CC::Channel_Volume, 2},
  {A2, MIDI_CC::Channel_Volume, 3},
  {A3, MIDI_CC::Channel_Volume, 4},
};

HystFilter hystFilters[] = {
  {1024, 128, 2}, // 10 bit ADC = 1024, 128 discrete output values required, margin = 2 units (of 1024)
  {1024, 128, 2},
  {1024, 128, 2},
  {1024, 128, 2},
};

const size_t nb_pots = sizeof(potentiometers) / sizeof(potentiometers[0]);
const size_t nb_hyst = sizeof(hystFilters) / sizeof(hystFilters[0]);
static_assert(nb_pots == nb_hyst, "Error: number of Analog potentiometers should be the same as the number of HystFilters");

void setup() {
  for (size_t i = 0; i < nb_pots; i++)
    potentiometers[i].map([i](int raw){ return (int) hystFilters[i].getOutputLevel(raw) << 3; });
}

void loop() {
  // Refresh the MIDI controller (check whether the potentiometer's input has changed since last time, if so, send the new value over MIDI)
  MIDI_Controller.refresh();
}

Compiled, but didn't test.


thanks for your help and time,


when i try to copy the code analog reading it gave me this error

fatal error: Analog.h: No such file or directory


and then when i try to create analog.h this error

fatal error: ../Settings/Settings.h: No such file or directory

thankss

PieterP

No, you don't have to copy the Analog.cpp file, that's just for reference.

You have to go to your ~/Arduino/libraries folder, and delete MIDI_Controller, then install git if you haven't already, and in the ~/Arduino/libraries folder, run
Code: [Select]
git clone -b lambda git@github.com:tttapa/MIDI_controller.git.

Then open the sketch I attached.


ciabio

No, you don't have to copy the Analog.cpp file, that's just for reference.

You have to go to your ~/Arduino/libraries folder, and delete MIDI_Controller, then install git if you haven't already, and in the ~/Arduino/libraries folder, run
Code: [Select]
git clone -b lambda git@github.com:tttapa/MIDI_controller.git.

Then open the sketch I attached.


thanks it says i dont have then access rights :

$ git clone -b lambda git@github.com:tttapa/MIDI_controller.git
Cloning into 'MIDI_controller'...
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


thanks


PieterP

#33
Apr 19, 2018, 12:25 pm Last Edit: Apr 19, 2018, 12:27 pm by PieterP
My bad, if you don't have an SSH key from your GitHub account, you have to use the HTTPS url:
Code: [Select]
git clone -b lambda https://github.com/tttapa/MIDI_controller.git

ciabio

My bad, if you don't have an SSH key from your GitHub account, you have to use the HTTPS url:
Code: [Select]
git clone -b lambda https://github.com/tttapa/MIDI_controller.git
okey thanks so now i have the sketch open,

whats the first thing i should write in the codes?

thankss




PieterP

okey thanks so now i have the sketch open,

whats the first thing i should write in the codes?

thankss

It's best to test that sketch first, with just 4 potentiometers, let me know if it works.

ciabio

It's best to test that sketch first, with just 4 potentiometers, let me know if it works.
thanks

the potentiometer flickering same as befor


PieterP

Try this. Change the factor of the EMA according to your sampling rate.


ciabio

Try this. Change the factor of the EMA according to your sampling rate.


thanks


I tried but no longer detects the potentiometers,
perhaps because of multiplexers?
no midi message is transmitted, first with the old code that you gave me it gaves the midi messages but trembled as usual

thanks a lot for your patience

PieterP

#39
Apr 19, 2018, 04:43 pm Last Edit: Apr 19, 2018, 04:44 pm by PieterP
It works on my Teensy 3.2 without multiplexers. Post your exact code, and post the schematic you're using with the multiplexers.

ciabio

It works on my Teensy 3.2 without multiplexers. Post your exact code, and post the schematic you're using with the multiplexers.
thanks


I copied exactly your code .. it remained the same, maybe I did not understand it. the schematic in the attach..it only a part of it but this is the way that i use to make the connection

PieterP

If you don't drive the address lines of those muxes, they're in an undefined state. Add an AnalogMultiplex object and use its pins.
AnalogMultiplex multiplexer(A0, { 2, 3, 4, 5 } );

Analog potentiometers[] = {
  {multiplexer.pin(0), MIDI_CC::Channel_Volume, 1},
  {multiplexer.pin(1), MIDI_CC::Channel_Volume, 2},
  {multiplexer.pin(2), MIDI_CC::Channel_Volume, 3},
  {multiplexer.pin(3), MIDI_CC::Channel_Volume, 4},
};

ciabio

If you don't drive the address lines of those muxes, they're in an undefined state. Add an AnalogMultiplex object and use its pins.
AnalogMultiplex multiplexer(A0, { 2, 3, 4, 5 } );

Analog potentiometers[] = {
  {multiplexer.pin(0), MIDI_CC::Channel_Volume, 1},
  {multiplexer.pin(1), MIDI_CC::Channel_Volume, 2},
  {multiplexer.pin(2), MIDI_CC::Channel_Volume, 3},
  {multiplexer.pin(3), MIDI_CC::Channel_Volume, 4},
};

its working you are my god :) :) thaaaaaaaankssss


so if i want to do this with all my pots.. ? how can i structurate the code'


thaaaanksss

PieterP

#43
Apr 19, 2018, 05:24 pm Last Edit: Apr 19, 2018, 05:34 pm by PieterP
If you want a clean solution, you'll have to wait untill I add the code to the library, or add it yourself. You could make your own Analog class, as explained on the Wiki. Take a look at Analog.h and Analog.cpp for inspiration. First try to understand how the code I posted works.

If you don't have that much time, just create the HystFilters manually, and use the Analog::map(std::function<int(int)>) function to apply them to all potentiometers. That's exactly what happens in the code I posted. Try to understand it first, and ask questions if you don't understand how it works.
Here are some comments:
Analog potentiometers[] = { // Create an array of 4 new Analog objects
  {multiplexer.pin(0), MIDI_CC::Channel_Volume, 1},
  {multiplexer.pin(1), MIDI_CC::Channel_Volume, 2},
  {multiplexer.pin(2), MIDI_CC::Channel_Volume, 3},
  {multiplexer.pin(3), MIDI_CC::Channel_Volume, 4},
};

HystFilter hystFilters[4]; // Create an array of 4 new HystFilter objects

// Make sure that the number of HystFilters and the number of Analog potentiometers are the same
const size_t nb_pots = sizeof(potentiometers) / sizeof(potentiometers[0]);
const size_t nb_hyst = sizeof(hystFilters) / sizeof(hystFilters[0]);
static_assert(nb_pots == nb_hyst, "Error: number of Analog potentiometers should be the same as the number of HystFilters");

void setup() {
  for (size_t i = 0; i < nb_pots; i++) // For all potentiometers
    // Apply a HystFilter to the analog value before sending it over MIDI
    potentiometers[i].map([i](int raw){ return (int) hystFilters[i].getOutputLevel(raw); });
    // Note that you need a different HystFilter for each potentiometer
}

If you don't understand the potentiometers[i].map(...) part, it's a capturing lambda expression (google it).

ciabio

#44
Apr 19, 2018, 07:19 pm Last Edit: Apr 19, 2018, 08:05 pm by ciabio Reason: add info

thanks

so i google it but i don't know where to put this function : Analog::map(std::function<int(int)>)

i watch the code and try to understand but its not easy...
every time i try to write somthing it gaves me a lot of error...
so thats the code that working befor errors

sorryyy for spending your time :(

thanks

Code: [Select]
#include <MIDI_Controller.h> // Include the library
#include "HystFilter.h"

// USBDebugMIDI_Interface udmi(115200);

AnalogMultiplex
multiplexer(A0, { 2, 3, 4, 5 } );


Analog potentiometers[] = {
  {multiplexer.pin(0), MIDI_CC::Channel_Volume, 1},
  {multiplexer.pin(1), MIDI_CC::Channel_Volume, 2},
  {multiplexer.pin(2), MIDI_CC::Channel_Volume, 3},
  {multiplexer.pin(3), MIDI_CC::Channel_Volume, 4},
  {multiplexer.pin(4), MIDI_CC::Channel_Volume, 5},
  {multiplexer.pin(5), MIDI_CC::Channel_Volume, 6},
  {multiplexer.pin(6), MIDI_CC::Channel_Volume, 7},
  {multiplexer.pin(7), MIDI_CC::Channel_Volume, 8},
  {multiplexer.pin(8), MIDI_CC::Channel_Volume, 9},
  {multiplexer.pin(9), MIDI_CC::Channel_Volume, 10},
  {multiplexer.pin(10), MIDI_CC::Channel_Volume, 11},
  {multiplexer.pin(11), MIDI_CC::Channel_Volume, 12},
  {multiplexer.pin(12), MIDI_CC::Channel_Volume, 13},
  {multiplexer.pin(13), MIDI_CC::Channel_Volume, 14},
  {multiplexer.pin(14), MIDI_CC::Channel_Volume, 15},
  {multiplexer.pin(15), MIDI_CC::Channel_Volume, 16},
};


HystFilter hystFilters[16];

const size_t nb_pots = sizeof(potentiometers) / sizeof(potentiometers[0]);
const size_t nb_hyst = sizeof(hystFilters) / sizeof(hystFilters[0]);
static_assert(nb_pots == nb_hyst, "Error: number of Analog potentiometers should be the same as the number of HystFilters");

void setup() {
  for (size_t i = 0; i < nb_pots; i++)
    potentiometers[i].map([i](int raw){ return (int) hystFilters[i].getOutputLevel(raw); });
}

void loop() {
  // Refresh the MIDI controller (check whether the potentiometer's input has changed since last time, if so, send the new value over MIDI)
  MIDI_Controller.refresh();
}

If you don't understand the potentiometers[i].map(...) part, it's a capturing lambda expression (google it).
i search it but i found only java scipts and other strange things

Go Up