Page 56 - MDP2022-2
P. 56

//pimMode  설정
                pinMode(7,OUTPUT);
                pinMode(8,OUTPUT);

                //블루투스와  아두이노의  통신속도를  9600으로  설정
                mySerial.begin(9600);

                Serial.println("Hello  World!");
            }

            void  loop()  {  //loop문

                byte  data;
                data  =  mySerial.read();
                    if(data  ==  'a'){    //컨트롤러가  오른쪽으로  기울어지면  우회전
                        digitalWrite(7,1);
                        digitalWrite(8,0);
                        Serial.println("우회전");
                        }else  if(data  ==  'b'){    //컨트롤러가  왼쪽으로  기울어지면  좌회전
                            digitalWrite(8,1);
                            digitalWrite(7,0);
                            Serial.println("좌회전");
                            }else  if(data  ==  'c'){    //컨트롤러가  중립이면  전진
                                digitalWrite(8,0);
                                digitalWrite(7,0);
                                Serial.println("전진");
                                }
              }

            본체  stm32  코드



            /*  USER  CODE  BEGIN  Header  */
            /**
                ******************************************************************************
                *  @file                      :  main.c
                *  @brief                    :  Main  program  body
                ******************************************************************************
                *  @attention
                *
                *  Copyright  (c)  2022  STMicroelectronics.
                *  All  rights  reserved.
                *
                *  This  software  is  licensed  under  terms  that  can  be  found  in  the  LICENSE  file
                *  in  the  root  directory  of  this  software  component.
                *  If  no  LICENSE  file  comes  with  this  software,  it  is  provided  AS-IS.
                *
                ******************************************************************************
                */
            /*  USER  CODE  END  Header  */
            /*  Includes  ------------------------------------------------------------------*/
            #include  "main.h"

            /*  Private  includes  ----------------------------------------------------------*/
            /*  USER  CODE  BEGIN  Includes  */
   51   52   53   54   55   56   57   58   59   60   61