Skip to content

Instantly share code, notes, and snippets.

@dali99
Last active May 5, 2017 10:59
Show Gist options
  • Save dali99/8b50e4d81dbf008cfffdac30cd4d0434 to your computer and use it in GitHub Desktop.
Save dali99/8b50e4d81dbf008cfffdac30cd4d0434 to your computer and use it in GitHub Desktop.
terning3.ino
#define D2 0
#define D3 1
#define D4 2
#define D5 3
#define D6 4
#define D7 5
#define D8 6
#define SW1 7
void setup()
{
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
pinMode(SW1, INPUT);
}
byte counter = 1;
void loop()
{
if (digitalRead(SW1) == LOW) {
show(0);
number = random(1, 7);
}
else {
show(counter);
}
}
void show(byte n) {
switch (n) {
case 0:
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);
digitalWrite(D4, LOW);
digitalWrite(D5, LOW);
digitalWrite(D6, LOW);
digitalWrite(D7, LOW);
digitalWrite(D8, LOW);
break;
case 1:
digitalWrite(D5, HIGH);
break;
case 2:
digitalWrite(D2, HIGH);
digitalWrite(D8, HIGH);
break;
case 3:
digitalWrite(D5, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D8, HIGH);
break;
case 4:
digitalWrite(D2, HIGH);
digitalWrite(D8, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D7, HIGH);
break;
case 5:
digitalWrite(D2, HIGH);
digitalWrite(D8, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D7, HIGH);
digitalWrite(D5, HIGH);
break;
case 6:
digitalWrite(D2, HIGH);
digitalWrite(D8, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D7, HIGH);
digitalWrite(D4, HIGH);
digitalWrite(D6, HIGH);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment