Skip to content

Instantly share code, notes, and snippets.

@jinks
Created March 21, 2017 06:23
Show Gist options
  • Save jinks/dbc7e4a6fba9e0e0438f2dc5f6ab99ee to your computer and use it in GitHub Desktop.
Save jinks/dbc7e4a6fba9e0e0438f2dc5f6ab99ee to your computer and use it in GitHub Desktop.
// Variant A
switch (state) {
case 1:
digitalWrite(P1Out, LOW); digitalWrite(P2Out, LOW);
break;
case 2:
digitalWrite(P1Out, LOW); digitalWrite(P2Out, HIGH);
break;
case 3:
case 4:
case 5:
case 6:
digitalWrite(P1Out, HIGH); digitalWrite(P2Out, HIGH);
break;
case 7:
case 8:
digitalWrite(P1Out, HIGH); digitalWrite(P2Out, LOW);
break;
case 9:
digitalWrite(P1Out, HIGH); digitalWrite(P2Out, HIGH);
break;
case 10:
digitalWrite(P1Out, LOW); digitalWrite(P2Out, HIGH);
break;
case 11:
case 12:
case 13:
digitalWrite(P1Out, HIGH); digitalWrite(P2Out, HIGH);
break;
case 14:
digitalWrite(P1Out, LOW); digitalWrite(P2Out, HIGH);
break;
case 15:
case 16:
digitalWrite(P1Out, HIGH); digitalWrite(P2Out, HIGH);
break;
}
//Variant B (reordered)
switch (state) {
case 1:
digitalWrite(P1Out, LOW); digitalWrite(P2Out, LOW);
break;
case 2:
case 10:
case 14:
digitalWrite(P1Out, LOW); digitalWrite(P2Out, HIGH);
break;
case 7:
case 8:
digitalWrite(P1Out, HIGH); digitalWrite(P2Out, LOW);
break;
case 3:
case 4:
case 5:
case 6:
case 9:
case 11:
case 12:
case 13:
case 15:
case 16:
digitalWrite(P1Out, HIGH); digitalWrite(P2Out, HIGH);
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment