Page 221 - MDP2022-3
P. 221

}


            void loop() {
                int action = 0;

                int re1_sum = digitalRead(re1);
                int re2_sum = digitalRead(re2);


                if(re1_sum == 0 && re2_sum == 0){

                  action = 1;
                }
                else if(re1_sum == 1 && re2_sum == 0){
                  action = 2;
                }
                else if(re1_sum == 0 && re2_sum == 1){

                  action = 3;
                }
                else if(re1_sum == 1 && re2_sum == 1){
                  action = 4;
                }

                Serial.println(action);


            //다리 움직임
                switch(action) {
                  case 1:// 서보모터 전진 동작

                    for(int i=0; i<50; i++){
                      servo0.write(i);
                      servo1.write(i);
                      st=i;
                      delay(5);

                    }
                    for(int a=0; a<50; a++){
                      servo2.write(a);
                      servo3.write(a);
                      st=a;

                      delay(5);
                    }
                    for(int j=50; j>0; j--){
                      servo0.write(j);
                      servo1.write(j);

                      st=j;
                      delay(5);
   216   217   218   219   220   221   222   223   224   225   226