Use the DIP switches - masonandrewmann/MEAP GitHub Wiki

The M.E.A.P. board has a package of 8 dip switches in the blue switch box near the power jack.

They are labelled as Switch #1 on the left through Switch #8 on the right

If you want to use the DIP switches, be sure that the readDip() function from MEAP_Hardware_Test is included at the bottom of your program and that it is called within updateControl() by including the following line:

readDip();

Also be sure that the Mux library is included and the relevant variables are defined at the top of your code (shown below)

#include <Mux.h>

using namespace admux;


// variables for DIP switches
Mux mux(Pin(34, INPUT, PinType::Digital), Pinset(16, 17, 12));
int dipPins[] = {5, 6, 7, 4, 3, 0, 2, 1};
int dipVals[] = {0, 0, 0, 0, 0, 0, 0, 0};
int prevDipVals[] = {0, 0, 0, 0, 0, 0, 0, 0};

All of this is done in the MEAP_Hardware_Test example so it is usually best to just use that program as a template.

The readDip() is designed to be edited by the user. If you want something to occur when a switch is moved you can simply add that code to the readDip() function in the location corresponding to the DIP switch you want to move. The meat of the function consists of 8 blocks that look like the following, each corresponding to a single DIP switch.

      case 0:
        if (dipVals[i] != prevDipVals[i]){
          if(!dipVals[i]){
            Serial.println("DIP 1 up");
          } else {
            Serial.println("DIP 1 down");
          }
        }
        break;

If you want something to occur when the switch is moved to the "up" position, add that code after the Serial.println("DIP 1 up"); line, while if you want something to occur when the switch is moved to the "down" position, add that code after the Serial.println("DIP 1 down"); line.

For example, maybe we want the switch to change the pitch of an oscillator between A4 when in the bottom position, and A5 when in the top position. The code to accomplish this will be as follows.

      case 0:
        if (dipVals[i] != prevDipVals[i]){
          if(!dipVals[i]){
            Serial.println("DIP 1 up");
            mySine.setFreq(880); // sets oscillator freq to 880 Hz (A5) when switch is moved up.
          } else {
            Serial.println("DIP 1 down");
            mySine.setFreq(440); // sets oscillator freq to 440 Hz (A4) when switch is moved down.
          }
        }
        break;

There may be a rare case where you want to refer to the value of the switches directly (ie. not just do something on a transition). You can access the values of the switches directly using the dipVals[] array and indexing between 0 and 7 for the switch numbers. To retrieve the value of Switch #1 use dipVals[0], dipVals[1] for Switch #2 etc. The value will be 0 when the switch is up and 1 when the switch is down.

⚠️ **GitHub.com Fallback** ⚠️