creative

세탁기 소스

아빠 2019.11.27 22:31 조회 수 : 16806

#!/usr/bin/env python

 

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(7, GPIO.IN) ## GPIO 7 Input For Water Sensor

GPIO.setup(8, GPIO.IN) ## GPIO 8 Input For Switch

GPIO.setup(11, GPIO.OUT) ## GPIO 11 output for Relay

 

## LED Setting

GPIO.setup(10, GPIO.OUT) ## GPIO 10 : Low Time Led

GPIO.setup(22, GPIO.OUT) ## GPIO 22 : Mid-Low Time Led

GPIO.setup(27, GPIO.OUT) ## GPIO 27 : MID-High Time Led

GPIO.setup(17, GPIO.OUT) ## GPIO 7 : High Time Led

 

## Init-section

def init_out():

  GPIO.output(11, False)

  GPIO.output(10, False)

  GPIO.output(22, False)

  GPIO.output(27, False)

  GPIO.output(17, True)

 

init_out()

 

run_time = 0

alern = 0

 

## On Time(2Hour) is 7200 seconds.

#on_time = 7200

 

## On Time(above 2Hour) is 8000 seconds.

on_time = 8000

 

while 1: ## Looping

    ## When Water Sensor clean(1)

    if GPIO.input(7) == 0: ## Water Detect

      alern = 1

      GPIO.output(11, False) ## Relay On

      if GPIO.input(10) == 0:

          GPIO.output(10, True)

          GPIO.output(22, True)

          GPIO.output(27, True)

      else:

          GPIO.output(10, False)

          GPIO.output(22, False)

          GPIO.output(27, False)

    else:

      if alern == 1:

        alern = 0

        GPIO.output(10, False)

        GPIO.output(22, False)

        GPIO.output(27, False)

 

    ## When Manual On

    if GPIO.input(8) == 1:

      if GPIO.input(11) == 0: ## When Relay off

        GPIO.output(11, True) ## Relay On

        run_time = 0

      else:

        GPIO.output(11, False) ## Relay Off

        GPIO.output(10, False)

        GPIO.output(22, False)

        GPIO.output(27, False)

 

    ## Time Led Status

    if GPIO.input(11) == 1:

      if ((run_time < (on_time / 4) * 1) & (run_time >= (on_time / 4) * 0)): ## Time Full : Blink High Led

        if GPIO.input(10) == 0:

          GPIO.output(10, True)

        else:

          GPIO.output(10, False)

 

        ## else LED ON

        GPIO.output(22, True)

        GPIO.output(27, True)

        GPIO.output(17, True)

 

      if ((run_time < (on_time / 4) * 2) & (run_time >= (on_time / 4) * 1)): ## Time Full : Blink High Led

        if GPIO.input(22) == 0:

          GPIO.output(22, True)

        else:

          GPIO.output(22, False)

 

        ## else LED ON

        GPIO.output(10, False)

        GPIO.output(27, True)

        GPIO.output(17, True)

 

      if ((run_time < (on_time / 4) * 3) & (run_time >= (on_time / 4) * 2)): ## Time Full : Blink High Led

        if GPIO.input(27) == 0:

          GPIO.output(27, True)

        else:

          GPIO.output(27, False)

 

        ## else LED ON

        GPIO.output(10, False)

        GPIO.output(22, False)

        GPIO.output(17, True)

 

      if ((run_time <= on_time) & (run_time >= (on_time / 4) * 3)): ## Time Full : Blink High Led

        if GPIO.input(17) == 0:

          GPIO.output(17, True)

        else:

          GPIO.output(17, False)

 

        ## else LED ON

        GPIO.output(10, False)

        GPIO.output(22, False)

        GPIO.output(27, False)

 

    ## When Times Up

    if run_time > on_time:

      init_out()

      run_time = 0

 

    ## For load down

    time.sleep(0.5) ## Wait one second

 

    run_time = run_time + 0.5

 

GPIO.cleanup() #GPIO Clean UP

menu