Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dynamic
#include <MsTimer2.h>
int led_a = 13;
int led_b = 12;
int led_c = 11;
int led_d = 10;
int led_e = 9;
int led_f = 8;
int led_g = 7;
int led_dp = 6;
int led_sel4 = 5;
int led_sel3 = 4;
int led_sel2 = 3;
int led_sel1 = 2;
int number;
void setup() {
pinMode(led_a, OUTPUT);
pinMode(led_b, OUTPUT);
pinMode(led_c, OUTPUT);
pinMode(led_d, OUTPUT);
pinMode(led_e, OUTPUT);
pinMode(led_f, OUTPUT);
pinMode(led_g, OUTPUT);
pinMode(led_dp, OUTPUT);
pinMode(led_sel3, OUTPUT);
pinMode(led_sel2, OUTPUT);
pinMode(led_sel1, OUTPUT);
randomSeed(analogRead(0)); // 未接続ピンのノイズを利用
number = random(99);
digitalWrite(led_sel3, LOW);
digitalWrite(led_sel2, LOW);
digitalWrite(led_sel1, LOW);
MsTimer2::set(100, update); // 500msごとにオンオフ
MsTimer2::start();
}
void update(){
randomSeed(analogRead(0)); // 未接続ピンのノイズを利用
number = random(100);
}
// the loop routine runs over and over again forever:
void loop() {
// if(number > 9) number = 0;
digitalWrite(led_sel2, HIGH);
lightLED(number/10);
delay(10);
digitalWrite(led_sel2, LOW);
digitalWrite(led_sel1, HIGH);
lightLED(number%10);
delay(10);
digitalWrite(led_sel1, LOW);
}
void lightLED(int num){
switch(num){
case 1:
digitalWrite(led_a, HIGH);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, HIGH);
digitalWrite(led_e, HIGH);
digitalWrite(led_f, HIGH);
digitalWrite(led_g, HIGH);
digitalWrite(led_dp, HIGH);
break;
case 2:
digitalWrite(led_a, LOW);
digitalWrite(led_b, LOW);
digitalWrite(led_c, HIGH);
digitalWrite(led_d, LOW);
digitalWrite(led_e, LOW);
digitalWrite(led_f, HIGH);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, HIGH);
break;
case 3:
digitalWrite(led_a, LOW);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, LOW);
digitalWrite(led_e, HIGH);
digitalWrite(led_f, HIGH);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, HIGH);
break;
case 4:
digitalWrite(led_a, HIGH);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, HIGH);
digitalWrite(led_e, HIGH);
digitalWrite(led_f, LOW);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, HIGH);
break;
case 5:
digitalWrite(led_a, LOW);
digitalWrite(led_b, HIGH);
digitalWrite(led_c, LOW);
digitalWrite(led_d, LOW);
digitalWrite(led_e, HIGH);
digitalWrite(led_f, LOW);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, LOW);
break;
case 6:
digitalWrite(led_a, HIGH);
digitalWrite(led_b, HIGH);
digitalWrite(led_c, LOW);
digitalWrite(led_d, LOW);
digitalWrite(led_e, LOW);
digitalWrite(led_f, LOW);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, HIGH);
break;
case 7:
digitalWrite(led_a, LOW);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, HIGH);
digitalWrite(led_e, HIGH);
digitalWrite(led_f, HIGH);
digitalWrite(led_g, HIGH);
digitalWrite(led_dp, LOW);
break;
case 8:
digitalWrite(led_a, LOW);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, LOW);
digitalWrite(led_e, LOW);
digitalWrite(led_f, LOW);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, HIGH);
break;
case 9:
digitalWrite(led_a, LOW);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, HIGH);
digitalWrite(led_e, HIGH);
digitalWrite(led_f, LOW);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, HIGH);
break;
case 0:
digitalWrite(led_a, LOW);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, LOW);
digitalWrite(led_e, LOW);
digitalWrite(led_f, LOW);
digitalWrite(led_g, HIGH);
digitalWrite(led_dp, HIGH);
break;
default:
digitalWrite(led_a, LOW);
digitalWrite(led_b, LOW);
digitalWrite(led_c, LOW);
digitalWrite(led_d, LOW);
digitalWrite(led_e, LOW);
digitalWrite(led_f, LOW);
digitalWrite(led_g, LOW);
digitalWrite(led_dp, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.