I made it for my practice of programing
int c;
int REC[]={0,0,0};
int checkND=0;
int newL[]={0,0,0};
int L=10;
int refleshT=1;
int vTime=500;
int amount7S =3;
void setup()
{
Serial.begin(9600);
for (int i=2; i<10; ++i){
pinMode(i,OUTPUT);
}
for (int i=10; i<13; ++i){
pinMode(i,INPUT);
}
for (int i=10; i<13; ++i){
digitalWrite(i,HIGH);
digitalWrite(i,LOW);
}
}
void loop()
{
if(Serial.available()>0){
BLOCK();
EXchecker();
if (checkND ==amount7S){
for(int FT=0; FT < vTime; ++FT){
for(int i=0; i<=3; i++){
L = newL[i]+10;
c = REC[i];
process();
}
}
}
nothing();
}
checkND = 0;
}
void zero(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
compress();
delay(refleshT);
}
void one(){
nothing();
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(refleshT);
}
void two(){
nothing();
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void three(){
nothing();
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
compress();
delay(refleshT);
}
void four(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(refleshT);
}
void five(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
delay(refleshT);
}
void six(){
nothing();
for(int i=2; i<=5; i++){
digitalWrite(i,HIGH);
}
digitalWrite(7,HIGH);
delay(refleshT);
}
void seven(){
nothing();
digitalWrite(2,HIGH);
compress();
delay(refleshT);
}
void eight(){
nothing();
for(int i=2; i<=5; i++){
digitalWrite(i,HIGH);
}
compress();
delay(refleshT);
}
void nine(){
nothing();
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
compress();
delay(refleshT);
}
void compress(){
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}
void nothing(){
reset();
for(int i=2; i<=9; i++){
digitalWrite(i,LOW);
}
delay(refleshT);
}
void reset(){
for (int e=10; e<13; ++e){
pinMode(e,INPUT);
}
}
void process(){
if(c=='8'){
pinMode(L,OUTPUT);
eight();
}
else if(c=='0'){
pinMode(L,OUTPUT);
zero();
}
else if(c=='1'){
pinMode(L,OUTPUT);
one();
}
else if(c=='2'){
pinMode(L,OUTPUT);
two();
}
else if(c=='3'){
pinMode(L,OUTPUT);
three();
}
else if(c=='4'){
pinMode(L,OUTPUT);
four();
}
else if(c=='5'){
pinMode(L,OUTPUT);
five();
}
else if(c=='6'){
pinMode(L,OUTPUT);
six();
}
else if(c=='7'){
pinMode(L,OUTPUT);
seven();
}
else if(c=='9'){
pinMode(L,OUTPUT);
nine();
}
else{
nothing();
return;
}
}
void BLOCK(){
for (int i=0; i<=2; i++){
REC[i]=Serial.read();
c = REC[i];
Cprocess();
newL[i]=i;
}
}
void EXchecker(){
if(Serial.available()>0){
int reader = Serial.read();
if(reader == -1){
}
else{
checkND = checkND +10;
}
}
}
void Cprocess(){
if(0<=c<=9){
checkND = checkND + 1;
}
else{
nothing();
return;
}
}
0 件のコメント:
コメントを投稿