【社員実践】プログラミングコード

たこ焼きPON☆PONの全プログラミングコードです。このままコピーしたりアレンジしたりして使ってみてください 。 コード説明は「ソレノイドで電子工作」で紹介しています。

int sol0=0;   //pinの名前付け 
int sol1=1;
int sol2=2;
int sol3=3;
int sol4=4;
int sol5=5;
int sol6=6;
int sol7=7;
int sol8=8;
int sol9=9;
int sol10=10;
int sol11=11;
int sol12=12;
int sol13=13;
int sol14=14;
int sol15=15;
int sol16=16;
int sol17=17;

int i=0;
int d=0;
int dh=0;
int dl=0;

void setup() {
pinMode(sol0,OUTPUT);   //0番PINをOUTPUTに設定
pinMode(sol1,OUTPUT);
pinMode(sol2,OUTPUT);
pinMode(sol3,OUTPUT);
pinMode(sol4,OUTPUT);
pinMode(sol5,OUTPUT);
pinMode(sol6,OUTPUT);
pinMode(sol7,OUTPUT);
pinMode(sol8,OUTPUT);
pinMode(sol9,OUTPUT);
pinMode(sol10,OUTPUT);
pinMode(sol11,OUTPUT);
pinMode(sol12,OUTPUT);
pinMode(sol13,OUTPUT);
pinMode(sol14,OUTPUT);
pinMode(sol15,OUTPUT);
pinMode(sol16,OUTPUT);
pinMode(sol17,OUTPUT);
}

void allHIGH() {
digitalWrite(sol0,HIGH);
digitalWrite(sol1,HIGH);
digitalWrite(sol2,HIGH);
digitalWrite(sol3,HIGH);
digitalWrite(sol4,HIGH);
digitalWrite(sol5,HIGH);
digitalWrite(sol6,HIGH);
digitalWrite(sol7,HIGH);
digitalWrite(sol8,HIGH);
digitalWrite(sol9,HIGH);
digitalWrite(sol10,HIGH);
digitalWrite(sol11,HIGH);
digitalWrite(sol12,HIGH);
digitalWrite(sol13,HIGH);
digitalWrite(sol14,HIGH);
digitalWrite(sol15,HIGH);
digitalWrite(sol16,HIGH);
digitalWrite(sol17,HIGH);
}

void allLOW() {
digitalWrite(sol0,LOW);
digitalWrite(sol1,LOW);
digitalWrite(sol2,LOW);
digitalWrite(sol3,LOW);
digitalWrite(sol4,LOW);
digitalWrite(sol5,LOW);
digitalWrite(sol6,LOW);
digitalWrite(sol7,LOW);
digitalWrite(sol8,LOW);
digitalWrite(sol9,LOW);
digitalWrite(sol10,LOW);
digitalWrite(sol11,LOW);
digitalWrite(sol12,LOW);
digitalWrite(sol13,LOW);
digitalWrite(sol14,LOW);
digitalWrite(sol15,LOW);
digitalWrite(sol16,LOW);
digitalWrite(sol17,LOW);
}

void LR() {
dh=100;
dl=dh*4;

for(i=0;i<2;i++){
digitalWrite(sol0,HIGH);
digitalWrite(sol1,HIGH);
digitalWrite(sol2,HIGH);
delay(dh);
digitalWrite(sol0,LOW);
digitalWrite(sol1,LOW);
digitalWrite(sol2,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol3,HIGH);
digitalWrite(sol4,HIGH);
digitalWrite(sol5,HIGH);
digitalWrite(sol6,HIGH);
delay(dh);
digitalWrite(sol3,LOW);
digitalWrite(sol4,LOW);
digitalWrite(sol5,LOW);
digitalWrite(sol6,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol7,HIGH);
digitalWrite(sol8,HIGH);
digitalWrite(sol9,HIGH);
digitalWrite(sol10,HIGH);
delay(dh);
digitalWrite(sol7,LOW);
digitalWrite(sol8,LOW);
digitalWrite(sol9,LOW);
digitalWrite(sol10,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol11,HIGH);
digitalWrite(sol12,HIGH);
digitalWrite(sol13,HIGH);
digitalWrite(sol14,HIGH);
delay(dh);
digitalWrite(sol11,LOW);
digitalWrite(sol12,LOW);
digitalWrite(sol13,LOW);
digitalWrite(sol14,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol15,HIGH);
digitalWrite(sol16,HIGH);
digitalWrite(sol17,HIGH);
delay(dh);
digitalWrite(sol15,LOW);
digitalWrite(sol16,LOW);
digitalWrite(sol17,LOW);
delay(dl);
}
}

void RL() {
dh=100;
dl=dh*4;

for(i=0;i<2;i++){
digitalWrite(sol15,HIGH);
digitalWrite(sol16,HIGH);
digitalWrite(sol17,HIGH);
delay(dh);
digitalWrite(sol15,LOW);
digitalWrite(sol16,LOW);
digitalWrite(sol17,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol11,HIGH);
digitalWrite(sol12,HIGH);
digitalWrite(sol13,HIGH);
digitalWrite(sol14,HIGH);
delay(dh);
digitalWrite(sol11,LOW);
digitalWrite(sol12,LOW);
digitalWrite(sol13,LOW);
digitalWrite(sol14,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol7,HIGH);
digitalWrite(sol8,HIGH);
digitalWrite(sol9,HIGH);
digitalWrite(sol10,HIGH);
delay(dh);
digitalWrite(sol7,LOW);
digitalWrite(sol8,LOW);
digitalWrite(sol9,LOW);
digitalWrite(sol10,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol3,HIGH);
digitalWrite(sol4,HIGH);
digitalWrite(sol5,HIGH);
digitalWrite(sol6,HIGH);
delay(dh);
digitalWrite(sol3,LOW);
digitalWrite(sol4,LOW);
digitalWrite(sol5,LOW);
digitalWrite(sol6,LOW);
delay(dl);
}

for(i=0;i<2;i++){
digitalWrite(sol0,HIGH);
digitalWrite(sol1,HIGH);
digitalWrite(sol2,HIGH);
delay(dh);
digitalWrite(sol0,LOW);
digitalWrite(sol1,LOW);
digitalWrite(sol2,LOW);
delay(dl);
}
}

void wave() {
d=100;

digitalWrite(sol0,HIGH);
digitalWrite(sol6,HIGH);
digitalWrite(sol7,HIGH);
digitalWrite(sol14,HIGH);
digitalWrite(sol15,HIGH);
delay(d);
digitalWrite(sol0,LOW);
digitalWrite(sol6,LOW);
digitalWrite(sol7,LOW);
digitalWrite(sol14,LOW);
digitalWrite(sol15,LOW);
delay(d);
digitalWrite(sol1,HIGH);
digitalWrite(sol5,HIGH);
digitalWrite(sol8,HIGH);
digitalWrite(sol13,HIGH);
digitalWrite(sol16,HIGH);
delay(d);
digitalWrite(sol1,LOW);
digitalWrite(sol5,LOW);
digitalWrite(sol8,LOW);
digitalWrite(sol13,LOW);
digitalWrite(sol16,LOW);
delay(d);
digitalWrite(sol2,HIGH);
digitalWrite(sol4,HIGH);
digitalWrite(sol9,HIGH);
digitalWrite(sol12,HIGH);
digitalWrite(sol17,HIGH);
delay(d);
digitalWrite(sol2,LOW);
digitalWrite(sol4,LOW);
digitalWrite(sol9,LOW);
digitalWrite(sol12,LOW);
digitalWrite(sol17,LOW);
delay(d);
digitalWrite(sol3,HIGH);
digitalWrite(sol10,HIGH);
digitalWrite(sol11,HIGH);
delay(d);
digitalWrite(sol3,LOW);
digitalWrite(sol10,LOW);
digitalWrite(sol11,LOW);
}

void spinP(){
d=100;
digitalWrite(sol0,HIGH);
delay(d);
digitalWrite(sol0,LOW);
digitalWrite(sol3,HIGH);
delay(d);
digitalWrite(sol3,LOW);
digitalWrite(sol7,HIGH);
delay(d);
digitalWrite(sol7,LOW);
digitalWrite(sol11,HIGH);
delay(d);
digitalWrite(sol11,LOW);
digitalWrite(sol15,HIGH);
delay(d);
digitalWrite(sol15,LOW);
digitalWrite(sol16,HIGH);
delay(d);
digitalWrite(sol16,LOW);
digitalWrite(sol17,HIGH);
delay(d);
digitalWrite(sol17,LOW);
digitalWrite(sol14,HIGH);
delay(d);
digitalWrite(sol14,LOW);
digitalWrite(sol10,HIGH);
delay(d);
digitalWrite(sol10,LOW);
digitalWrite(sol6,HIGH);
delay(d);
digitalWrite(sol6,LOW);
digitalWrite(sol2,HIGH);
delay(d);
digitalWrite(sol2,LOW);
digitalWrite(sol1,HIGH);
delay(d);
digitalWrite(sol1,LOW);
digitalWrite(sol4,HIGH);
delay(d);
digitalWrite(sol4,LOW);
digitalWrite(sol8,HIGH);
delay(d);
digitalWrite(sol8,LOW);
digitalWrite(sol12,HIGH);
delay(d);
digitalWrite(sol12,LOW);
digitalWrite(sol13,HIGH);
delay(d);
digitalWrite(sol13,LOW);
digitalWrite(sol9,HIGH);
delay(d);
digitalWrite(sol9,LOW);
digitalWrite(sol5,HIGH);
delay(d);
digitalWrite(sol5,LOW);
}

void spinN(){
d=100;
digitalWrite(sol5,HIGH);
delay(d);
digitalWrite(sol5,LOW);
digitalWrite(sol9,HIGH);
delay(d);
digitalWrite(sol9,LOW);
digitalWrite(sol13,HIGH);
delay(d);
digitalWrite(sol13,LOW);
digitalWrite(sol12,HIGH);
delay(d);
digitalWrite(sol12,LOW);
digitalWrite(sol8,HIGH);
delay(d);
digitalWrite(sol8,LOW);
digitalWrite(sol4,HIGH);
delay(d);
digitalWrite(sol4,LOW);
digitalWrite(sol1,HIGH);
delay(d);
digitalWrite(sol1,LOW);
digitalWrite(sol2,HIGH);
delay(d);
digitalWrite(sol2,LOW);
digitalWrite(sol6,HIGH);
delay(d);
digitalWrite(sol6,LOW);
digitalWrite(sol10,HIGH);
delay(d);
digitalWrite(sol10,LOW);
digitalWrite(sol14,HIGH);
delay(d);
digitalWrite(sol14,LOW);
digitalWrite(sol17,HIGH);
delay(d);
digitalWrite(sol17,LOW);
digitalWrite(sol16,HIGH);
delay(d);
digitalWrite(sol16,LOW);
digitalWrite(sol15,HIGH);
delay(d);
digitalWrite(sol15,LOW);
digitalWrite(sol11,HIGH);
delay(d);
digitalWrite(sol11,LOW);
digitalWrite(sol7,HIGH);
delay(d);
digitalWrite(sol7,LOW);
digitalWrite(sol3,HIGH);
delay(d);
digitalWrite(sol3,LOW);
digitalWrite(sol0,HIGH);
delay(d);
digitalWrite(sol0,LOW);
}

void loop() {
delay(1000);
allHIGH();
delay(100);
allLOW();
delay(1000);

for(i=0;i<2;i++){
LR(); //left-right
RL(); //right-left
}

delay(1000);
allHIGH();
delay(100);
allLOW();
delay(1000);

for(i=0;i<2;i++){
wave();
}

delay(1000);
allHIGH();
delay(100);
allLOW();
delay(1000);

for(i=0;i<2;i++){
delay(1000);
spinP();
delay(1000);
spinN();
}

あわせて読みたい

1件の返信

コメントを残す

メールアドレスが公開されることはありません。