Page 28 - MDP2022-2
P. 28

#define  coin_in                      8
            #define  poto_2                        7
            #define  Solenoide_INPUT      18


            Servo  servo;


            int  flag  =  0,  flag_sol  =  0,  angle  =  0;


            void  setup()  {
                Serial.begin(115200);

                pinMode(mp3,  INPUT);
                pinMode(Solenoide_INPUT,  INPUT);
                pinMode(Solenoide_OUTPUT,  OUTPUT);
                //pinMode(restart_pin,  INPUT_PULLUP);
                pinMode(coin_in,  INPUT);
                pinMode(poto_2,  INPUT);
                servo.attach(servopin);
                servo.write(0);


                Wire.begin(I2C_address);                            //  I2C  슬라이브  address  #2
                //Wire.onReceive(I2C_receiveEvent);          //  I2C  이벤트  발생시  실행할  함수지정(실행명령:머머해라)


                mp3_play(1);
            }


            void  loop()  {
                int  coin_state        =  digitalRead(coin_in);
                int  poto_state  =  digitalRead(poto_2);
                /*Serial.print("coin  state:  ");
                    Serial.print(coin_state);
                    Serial.print("  restert_pin:  ");
                    Serial.println(restart_pin);*/


                if  (coin_state  ==  1)  {
                    while  (1)  {
                        Serial.println("동전  먹음");
                        int  temp  =  digitalRead(coin_in);
                        if  (temp  ==  0)  break;
                    }
                    digitalWrite(Solenoide_OUTPUT,  HIGH);
                    servo.write(70);
                    delay(400);
                    servo.write(0);
                    flag_sol  =  1;
   23   24   25   26   27   28   29   30   31   32   33