• Multiplexer pot reading

    Lee Sampson11/10/2022 at 15:24 0 comments

    Wanted to test the speed difference between using a multiplexer to read multiple potentiometers from one analog pin vs having them on individual pins.

    Code I used. Reads pot 8 times via multiplexer and prints time, then reads pot 8 times the normal way and prints time.

    #define number_of_mux 1
    #define numOfMuxPins number_of_mux * 8
    #define channelA 2
    #define channelB 3
    #define channelC 4
    #define comPin 14
    
    int analogVal[8];
    unsigned long timer; 
    
    
    void setup() 
    {
    
      Serial.begin(9600);
    
      pinMode(channelA, OUTPUT);
      pinMode(channelB, OUTPUT); 
      pinMode(channelC, OUTPUT); 
      pinMode(comPin, INPUT);
      digitalWrite(channelA, LOW);
      digitalWrite(channelB, LOW);
      digitalWrite(channelC, LOW);
    
      MuxRead();
      //delay(4000);
    
      normalRead();
      //delay(4000);
    
    }
    
    void loop() 
    {
    
    }
    
    void selectChannel(int chnl)
    { //// Select channel of the multiplexer 
    
      int A = bitRead(chnl,0); //Take first bit from binary value of i channel.
      int B = bitRead(chnl,1); //Take second bit from binary value of i channel.
      int C = bitRead(chnl,2); //Take third bit from value of i channel.
    
      digitalWrite(channelA, A);
      digitalWrite(channelB, B);
      digitalWrite(channelC, C);
     
    }
    
    void MuxRead()
    {
      timer = micros();
    
      for(int i = 0; i <  numOfMuxPins; i++)
      {
        selectChannel(i);
        analogVal[i] = analogRead(comPin);
      }
    
      timer = micros() - timer;
      Serial.print("muxRead = ");
      Serial.println(timer);
      Serial.println("**************************************");
    }
    
    void normalRead()
    {
      timer = micros();
    
      for(int i = 0; i <  numOfMuxPins; i++)
      {
        analogVal[i] = analogRead(comPin);
      }
    
      timer = micros() - timer;
      Serial.print("normalRead = ");
      Serial.println(timer);
      Serial.println("**************************************");
    }
    

    Results (in micros):

    muxRead = 141
    **************************************
    normalRead = 140
    **************************************

     Multiplexer schematic:

  • Menu system WIP

    Lee Sampson11/10/2022 at 15:09 0 comments

    As part of the sampler I am developing a menu system that can incorporate different types of menu layouts and functionalities based on the same input controls. 

    Menus I want to make:

    - Main menu (scrolling menu in video)

    - File selector for selecting files from SD card (in video)

    - Bank and slot "grid". Want an easy way of selecting sample slots and copying and pasting them. (in video)

    - 8 Channel mixer for volume control and effects

    - Midi settings menu 

    - Sample trimming for editing start and end of sample

    - Sample recording menu

    I will be uploading code soon once it's in a better place.

    Test rig for developing the menu types. I will eventually use an encoder but just have buttons for left, right and click for now.

    A couple of menus that I've made. Still very much WIP.

  • Class inheritance for menu system

    Lee Sampson10/14/2022 at 15:11 0 comments

    #include <vector>
    #include <iostream>
    #include <memory>
    
    class can_display {
    public:
      virtual void display() = 0;
      virtual ~can_display() = default;
    };
    
    class A : public can_display 
    {
      void display() override
      {
        // display something
        std::cout << "Display from A\n";
      }
    };
    
    class B : public can_display 
    {
      void display() override
      {
        // display something two
        std::cout << "Display from B\n";
      }
    };
    
    
    int main()
    {
        can_display* a = new A();
        can_display* b = new B();
    
        can_display* array[2] = {a, b};
    
        array[0]->display();
        array[1]->display();
    
    }

    Test code to have multiple menu subclasses within one overall menu class. Essentially allows you to have different classes with the same functions within an array. You can then have something like this:

    menu[x].display();

    So each menu subclass in the array can be selected and then the function "display()" can be run.

    Will update with actual menu based example