// Forum: https://forum.arduino.cc/t/problem-with-dipswitches-using-an-atmega328/1247036
// This Wokwi project: https://wokwi.com/projects/394989876184507393

const byte dipSwitchPins[] = {4, 5};  // Pins for dip switches

void setup() 
{
  Serial.begin(115200);

  pinMode(dipSwitchPins[0], INPUT_PULLUP);  // Dip switch 1
  pinMode(dipSwitchPins[1], INPUT_PULLUP);  // Dip switch 2
}

void loop() 
{
  // Read dip switches to set MIDI channel
  byte dipSwitchState = digitalRead(dipSwitchPins[0]) | (digitalRead(dipSwitchPins[1]) << 1);
  int channelNo = map(dipSwitchState, 0, 3, 1, 2);

  Serial.print("dipSwitchState=");
  Serial.print(dipSwitchState);
  Serial.print(", channelNo=");
  Serial.println(channelNo);
  delay(800);
}