• arduino代码示范


    arduino代码示范

    //txwtech@163.com
    //2020/03/25
    //txwtech@163.com
    //2020/03/25
    //2020/06/25
    //2020/09/14
    // constants won't change. They're used here to set pin numbers:
    #include <SoftwareSerial.h>
    const int in_doorOpenState = 4;//arduino pin 4
    const int in_doorCloseState = 5;
    const int in_rFinish=6;//receive Finish signal
    const int in_mOperation=7;//manual operation.
    const int in_pStart=8;//program start;
    const int in_safeScreen=9;//door safety sensor
    const int Out_doorClose=10;
    const int Out_PowerUV=11; //control one relay, make UV to work
    //const int Out_PowerUV=3;
    int in_doorOpenStateV=1; //v--value,//must initialize value to 1.
    int in_doorCloseStateV=1;//must initialize value to 1.
    int in_rFinishV=1;
    int in_mOperationV=1;
    int in_pStartV=1;
    int in_safeScreenV=1;
    String inputString1="";
    bool doorCloseBool=false;
    bool uvFinishBool=false;
    void programStarted();
    void programStarted_m();
    SoftwareSerial softSerial(12,13);//RX:12,TX:13
    
    void programStarted()
    {
       in_pStartV=digitalRead(in_pStart);
        if(LOW==in_pStartV)
         {  //1
          doorCloseBool=true;//new added
          while(doorCloseBool)//new added
              {//2    ----------------------------------------------------------    
                          delay(100);
                          in_doorOpenStateV=digitalRead(in_doorOpenState);
                          in_safeScreenV=digitalRead(in_safeScreen);
                          if((LOW==in_doorOpenStateV)&&(LOW==in_safeScreenV))
                         
                           {
                               digitalWrite(Out_doorClose,HIGH);//  normal close
                              // delay(2000);//waiting for door close  
                                     
                           }
                           in_safeScreenV=digitalRead(in_safeScreen);
                            if(LOW!=in_safeScreenV)
                            {
                            digitalWrite(Out_doorClose,LOW);//  not safe, door open
                           // doorCloseBool=false;   //2020/09/14
                            }
                           
                           
                           in_doorCloseStateV=digitalRead(in_doorCloseState);
                           if(LOW==in_doorCloseStateV)
                           {
                               doorCloseBool=false; 
                           }
                           
                         
              }//2   
                           in_doorCloseStateV=digitalRead(in_doorCloseState);
                           if(LOW==in_doorCloseStateV)
                        {
                            digitalWrite(Out_PowerUV,HIGH);//脚踏板,启动UV
                            delay(2000);
                            digitalWrite(Out_PowerUV,LOW);
                           // delay(2000); 
                            uvFinishBool=true;             
                        }   
                while(uvFinishBool)
                {
                     delay(100);
                     if(LOW!=digitalRead(in_rFinish))//24VDC X4灯,表示LOW状态,固化中。 灯灭变成HIGH,!=LOW固化结束。
                        {
                           digitalWrite(Out_doorClose,LOW);//  door open
                           uvFinishBool=false;
                        }
                     
                }
               
         
         }//1
    }
    void programStarted_m()
    {
       in_pStartV=digitalRead(in_pStart);
        if(LOW==in_pStartV)
         {  //1
    
                            digitalWrite(Out_PowerUV,HIGH);//脚踏板,启动UV
                            delay(2000);
                            digitalWrite(Out_PowerUV,LOW);                   
                            uvFinishBool=true;             
          }   
                while(uvFinishBool)
                {
                  delay(100);
                     if(LOW!=digitalRead(in_rFinish))//24VDC X4灯,表示LOW状态,固化中。 灯灭变成HIGH,!=LOW固化结束。
                        {
                        //   digitalWrite(Out_doorClose,LOW);//  door open
                           uvFinishBool=false;
                        }
                     
                }
               
         
        
    }
    void setup() 
    {
      // initialize the LED pin as an output:
      //delay(2000);
      softSerial.begin(9600);
      softSerial.listen();
      
       pinMode(Out_doorClose, OUTPUT);//10
       pinMode(Out_PowerUV, OUTPUT);//11
     
      // initialize the pushbutton pin as an input:
       pinMode(in_doorOpenState, INPUT_PULLUP);//4,LOW means have signal
       pinMode(in_doorCloseState, INPUT_PULLUP);//5
       pinMode(in_rFinish, INPUT_PULLUP);//6
       pinMode(in_mOperation, INPUT_PULLUP);//7
       pinMode(in_pStart, INPUT_PULLUP);//8
       pinMode(in_safeScreen, INPUT_PULLUP);//9-------------
       digitalWrite(Out_doorClose,LOW);
       digitalWrite(Out_PowerUV,LOW);
       doorCloseBool=false;
       uvFinishBool=false;
    
    
       in_doorOpenStateV=1; //v--value,//must initialize value to 1.
       in_doorCloseStateV=1;//must initialize value to 1.
       in_rFinishV=1;
       in_mOperationV=1;
       in_pStartV=1;
       in_safeScreenV=1;
      
     
    }
    
    void loop() 
    {
       //UVsignal();
       in_doorOpenStateV=digitalRead(in_doorOpenState);
      // in_doorCloseStateV=digitalRead(in_doorCloseState);
       
       in_mOperationV=digitalRead(in_mOperation);
       in_pStartV=digitalRead(in_pStart);
      // in_safeScreenV=digitalRead(in_safeScreen);
       
       //for auto-----------------------------------auto----------
      if(digitalRead(in_mOperation)!=LOW) //non-manual is auto
      {
        programStarted();
        
      }//auto end
      //for manual opeation--------------------------manual----------
      else if(LOW==digitalRead(in_mOperation))
      {
            digitalWrite(Out_doorClose,LOW);//open door,
            programStarted_m();
        
      }//manual end,    
    }//---loop end
     void UVsignal()
     {
      inputString1 = "";
      if(softSerial.available()>0)
      {
        if(softSerial.peek()!='
    ')
        {    
          inputString1+=(char)softSerial.read();
         // softSerial.print("reply:");
         // softSerial.println(inputString1);
        // digitalWrite(Out_doorClose,LOW);
        //  delay(2000);
          
        }  
      }  
      }
     
  • 相关阅读:
    370 (区间加法)差分数组
    219. 存在重复元素 II
    438. 找到字符串中所有字母异位词
    410. 分割数组的最大值
    632. 最小区间
    689. 三个无重叠子数组的最大和
    java并发编程之CompletionService(转载)
    java通过jdbc连接hive并实时获取日志(转)
    java设计模式之职责链模式(二)
    Spring事件监听(转)
  • 原文地址:https://www.cnblogs.com/txwtech/p/13670268.html
Copyright © 2020-2023  润新知