Example #1
0
def ON():
    Enable = 1
    GPIO.output(Enable_pin, Enable)
    time.sleep(2)
    dc = 40
    p.ChangeDutyCycle(dc)
    time.sleep(2)
Example #2
0
class GpsPoller(threading.Thread):
        def __init__(self):
                threading.Thread.__init__(self)
        global gpsd #bring it in scope
        gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
        self.current_value = None
        self.running = True #setting the thread running to true
        def run(self):
                global gpsd
        while gpsp.running:
                gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
	if __name__ == '__main__':
        	gpsp = GpsPoller() # create the thread
        try:
                gpsp.start() # start it up
                while True:
                #It may take a second or two to get good data
                        print ' GPS mode:'
                        print '----------------------------------------'
                        print 'mode        ' , gpsd.fix.mode # all values greather than 1 is a GPS fix.
                while True:
			if gpsmode > 1:
				GPIO.output(24, True)
		if gpsmode < 1:
			GPIO.output(24, False)
Example #3
0
 def encoder_run(self):
     GPIO.add_event_detect(self.encoder_pinA,
                           GPIO.BOTH,
                           callback=self.encoder_A)
     GPIO.add_event_detect(self.encodef_pinB,
                           GPIO.BOTH,
                           callback=self.encoder_B)
Example #4
0
 def do_GET(s):
     s.send_response(200)
     s.send_header("Content-type", "text/plain")
     s.end_headers()
     GPIO.output(INTERCOM_PIN, 1)
     time.sleep(2)
     GPIO.output(INTERCOM_PIN, 0)
Example #5
0
    def __init__(self, pins, mode=3):
        """Initialise the motor object.

        pins -- a list of 4 integers referring to the GPIO pins that the IN1, IN2
                IN3 and IN4 pins of the ULN2003 board are wired to
        mode -- the stepping mode to use:
                1: wave drive (not yet implemented)
                2: full step drive
                3: half step drive (default)

        """
        self.p1 = pins[0]
        self.p2 = pins[1]
        self.p3 = pins[2]
        self.p4 = pins[3]
        self.mode = mode

        # These stuff that i don't understand
        self.deg_per_step = 5.625 / 64  # For half-step drive (mode 3), means deg for each step
        self.steps_per_rev = int(360 / self.deg_per_step)
        self.step_angle = 0  # Assume the way it is pointing is zero degrees

        for pin in pins:
            GPIO.setup(p, GPIO.OUT)
            GPIO.output(pin, False)
Example #6
0
def PARAR():
	# MOTOR 1
	GPIO.OUTPUT(MD1 ,1) # IN1
	GPIO.OUTPUT(MD2 ,1) # IN2
	# MOTOR 2
	GPIO.OUTPUT(ME1 ,1) # IN3
	GPIO.OUTPUT(ME2 ,1) # IN4
 def __init__(self, rateInSec = 1):
     super(SimpleLedActivator, self).__init__()
     if rateInSec > 0:
         self.rateInSec = rateInSec
     
     GPIO.setmode(GPIO.BCM)
     GPIO.setup(17, GPIO.OUT)
Example #8
0
def ChangeDirection():
    if Direction == True:
        GPIO.output(MotorDirectionList, False)
        print("Change Direction True → False")

    if Direction == False:
        GPIO.output(MotorDirectionList, True)
        print("Change Direction False → True")
Example #9
0
def main():
    kruispuntnr = 1
    einde = False   # True waarde nog te implementeren
    GPIO.setmode(GPIO.BOARD)

    # SPI-object maken voor afstandssensor
    CE = 0  # Eerste kanaal op ADC selecteren
    spi = spidev.SpiDev0(0, CE)
    spi.max_speed_hz = 1000000
    kanaal = 0  # Eerste analoge signaal

    # Kleurensensor initialiseren
    i2c = busio.I2C(5, 3)
    kleurensensor = Adafruit_TCS34725.TCS34725(i2c)

    # Server initialiseren
    server = Server.Server()

    last_error = 0  # Nodig voor de eerst keer volglijn uit te voeren
    while not einde:
        while True:
            # Manuele override
            message = server.listen()
            if message:
                last_error = 0
                break

            # Volg de lijn 10 keer
            for i in range(10):
                returnwaarde = lijninterpretatie()
                if returnwaarde == "stopstreep":
                    stopMotor()
                    kruispunt(kruispuntnr, kleurensensor, kanaal)
                    kruispuntnr += 1
                    last_error = 0  #Herinitialisatie van lijnvolgalgoritme
                else:
                    volglijn(returnwaarde)

            # Na 10 maal lijn te volgen, check de sensoren
            if adc.getAfstand(kanaal) < 15:
                stopMotor()
                while adc.getAfstand(kanaal) < 20:
                    pass

        #Bericht uitlezen
        while message != 'Ga door':
            if message == 'rechtdoor':
                forward(10)
                time.sleep(0.0000001)
                stopMotor()
                message = server.listen()
            elif  message == 'links':
                pass

            message = server.listen()

        raise Exception("Fout in de code.")
Example #10
0
File: run.py Project: OAmAr/EpiPing
def main():
    pin = 23
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(pin, GPIO.IN)
    message = "Hi %s, this is %s, %s %s" %
        ( data["Emergency Contact Name"],
          data["My Name"],
          data["Message"],
          data["Location"])
Example #11
0
def readPin(pin):
	try:
		GPIO.setup(int(pin),GPIO.IN)
		if GPIO.setup(int(pin)) == True:
        		response = "Pin number " + pin + " is high !"
                else :
			response = "Pin number " + pin + " is low !"
		except :  
			response = "There was an error reading Pin " + pin + " . "
 def run(self):
     while True:
         if self.enableLed:
             #we output the leds
             GPIO.output(17, GPIO.HIGH)
             sleep(self.rateInSec)
             GPIO.output(17, GPIO.LOW)
         
         sleep(self.rateInSec)
Example #13
0
def RE(tempo):
	t=float(tempo)
	# MOTOR 1
	GPIO.OUTPUT(MD1 ,0) # IN1
	GPIO.OUTPUT(MD2 ,1) # IN2
	# MOTOR 2
	GPIO.OUTPUT(ME1 ,0) # IN3
	GPIO.OUTPUT(ME2 ,1) # IN4
	time.sleep(t)
	PARAR()
Example #14
0
def close(m):
    """Turns off relay on pin 18"""

    if (int(time.time()) - time_ignore) > m.date:
        return

    if (m.chat.id in allowed_numbers):
        door.send_chat_action(m.chat.id, 'typing')
        door.send_message(m.chat.id, 'Door closed')

        GPIO.output(18, 0)
Example #15
0
    def detect(self):
        detectColor = "Error"

        if GPIO.input(self.__TrackPin) == GPIO.LOW:
            detectColor = "White"
            GPIO.output(self.__LedPin, GPIO.LOW)
        else:
            detectColor = "Black"
            GPIO.output(self.__LedPin, GPIO.HIGH)

        return detectColor
Example #16
0
def keep_open(m):
    """Keeps the relay on pin 18 active until manually turned off"""

    if (int(time.time()) - time_ignore) > m.date:
        return

    if (m.chat.id in allowed_numbers):
        door.send_chat_action(m.chat.id, 'typing')
        door.send_message(m.chat.id,
                          'Door will be kept opened until further indicated')

        GPIO.output(18, 1)
Example #17
0
def ROTA(tempo,dir):
	t=float(tempo)
	d=int(dir)
	IF d == 1: #direita 
		# MOTOR 1
		GPIO.OUTPUT(MD1 ,0) # IN1
		GPIO.OUTPUT(MD2 ,1) # IN2
		# MOTOR 2
		GPIO.OUTPUT(ME1 ,1) # IN3
		GPIO.OUTPUT(ME2 ,0) # IN4
		time.sleep(t)
		PARAR()
Example #18
0
def open_portal(m):
    """Activates a relay on GPIO pin 18 for 3 seconds"""

    if (int(time.time()) - time_ignore) > m.date:
        return

    if (m.chat.id in allowed_numbers):
        door.send_chat_action(m.chat.id, 'typing')
        door.send_message(m.chat.id, 'Door opened')

        GPIO.output(18, 0)
        time.sleep(3)
        GPIO.output(18, 1)
Example #19
0
def motor_effect_thread():
    global trigger_motor_effect
    GPIO.setmode(GPIO.BOARD)  # Number GPIOs by physical location
    GPIO.setup(config.MOTOR_PIN, GPIO.OUT)  # Set motor_pin mode is output
    GPIO.output(config.MOTOR_PIN, GPIO.LOW)  # Set motor_pin to low(0V)

    while True:
        time.sleep(constant.MOTOR_UPDATE_DELAY)
        if trigger_motor_effect == constant.START_COMMAND:
            GPIO.output(config.MOTOR_PIN, GPIO.HIGH)
            time.sleep(config.MOTOR_EFFECT_DELAY)
            GPIO.output(config.MOTOR_PIN, GPIO.LOW)
            trigger_effect(constant.MOTOR_EFFECT_TARGET, constant.STOP_COMMAND)
def lights(action):
    if(action=="on"):
        GPIO.output(3, GPIO.HIGH)
        GPIO.output(2, GPIO.LOW)
    elif(action=="off"):
        GPIO.output(2, GPIO.HIGH)
        GPIO.output(3, GPIO.LOW)
Example #21
0
def ObratD(MoveTime):
	gpio.output(MotorLevoNaprej, gpio.HIGH)
	gpio.output(MotorLevoNazaj, gpio.LOW)
	gpio.output(MotorDesnoNaprej, gpio.LOW)
	gpio.output(MotorDesnoNazaj, gpio.HIGH)
	time.sleep(MoveTime)
	return
Example #22
0
    def __init__(self, TRIGGER, ECHO):
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        self.GPIO_TRIGGER = TRIGGER
        self.GPIO_ECHO = ECHO

        GPIO.setup(self.GPIO_TRIGGER, GPIO.OUT)
        GPIO.setup(self.GPIO_ECHO, GPIO.IN)
Example #23
0
def monitor(m):
    """Checks for intruders with a magnetic reed switch on pin 23.

      If trespassing is detected, pictures are taken and sent until
      the sensor is inactive again.
   """
    if (int(time.time()) - time_ignore) > m.date:
        return

    if (m.chat.id in allowed_numbers):
        door.send_message(m.chat.id, 'Door monitor enabled')
        global active
        active = True

        while active:
            if (GPIO.input(23) == 0):
                door.send_message(m.chat.id, 'Someone has entered!')
                os.system('raspistill -o /home/pi/pic.jpg -t 1')
                toCrop = Image.open('/home/pi/pic.jpg')

                half_the_width = toCrop.size[0] / 2
                half_the_height = toCrop.size[1] / 2
                img = toCrop.crop(
                    (half_the_width - 400, half_the_height - 60,
                     half_the_width + 300, half_the_height + 640))
                img.save('/home/pi/picCrop.jpg')

                photo = open('/home/pi/picCrop.jpg', 'rb')
                door.send_photo(m.chat.id, photo)
                photo.close()
            time.sleep(2)
def launchSequence(distance, yawAngle):

    print "\n%sm away" % distance
    print "%s degrees\n" % yawAngle

    adjustYawAngle(yawAngle)
    adjustPitchAngle(distance)

    #Basic kinematics to calculate the force at which the
    #launching mechanism needs to propell the object at
    power = 0  #value of calculation go here

    shoot(power)

    pwm.stop()
    GPIO.cleanup()
Example #25
0
def readPin(pin):
	try:
		GPIO.setup(int(pin),GPIO.IN)
		if GPIO.setup(int(pin)) == True:
   			response = "Pin number " + pin + " is high !"
		else :
			response = "Pin number " + pin + " is low !"

		templateData = {
		'title' : 'Status of hardware Pin ' + pin , 
'		response' : response 
		}

		return render_template('pin.html', **templateData)	
	if __name__ == "__pin__":
	  app.run(host='0.0.0.0', port=80, debug=True) 
Example #26
0
 def __init__(self):
     self.pinA = 0
     self.pinB = 0
     # 선 배선 확인
     #    - - - - - - - - - - -
     #   |   @@@              |
     #   | A @@@            B |
     #    - - - - - - - - - - -
     # A가 눌리면 열림
     # B가 눌리면 닫침
     GPIO.setup(self.pinA, GPIO.IN)
     GPIO.setup(self.pinB, GPIO.IN)
     #초기 설정
     self.A_stat = True
     self.B_stat = False
     self.checking()
def checkStartButton():
    btnState = GPIO.input (startBtn)
    #if the last reading was low and this one high, print
    if (prevBtnState == False and btnState == True):		# Button is pressed
        startBtnPressed = True
    prevBtnState = btnState
    time.sleep(0.05)
Example #28
0
 def init_pin_direction(self):
     io.setmode(io.BCM)
     io.setwarnings(False)
     io.setup(23, io.OUT)
     io.setup(24, io.OUT)
     bulb_data_direction = digitalio.DigitalInOut(board.D5)
     bulb_data_direction.direction = digitalio.Direction.OUTPUT
     movement_sensor_pin_direction = digitalio.DigitalInOut(board.D2)
     movement_sensor_pin_direction.direction = digitalio.Direction.INPUT
Example #29
0
    def __init__(self):
        self.cone_pul = 
        self.cone_dir = 
        self.reel_pul =
        self.reel_dir = 

        self.table_pwm = 
        self.table_in1 = 
        self.table_in2 = 
        self.table_en =

        self.limit_pin = 
        GPIO.setup(self.limit_pin, GPIO.IN)
        self.contact_pin = 
        GPIO.setup(self.contact_pin, GPIO.IN)
        self.table_hall_pin = 
        GPIO.setup(self.table_hall_pin, GPIO.IN)
Example #30
0
def setup():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(Buzzer, GPIO.OUT)  # Set pins' mode is output
    global Buzz  # Assign a global variable to replace GPIO.PWM
    Buzz = GPIO.PWM(Buzzer, 440)  # 440 is initial frequency.
    Buzz.start(50)  # Start Buzzer pin with 50% duty ration
Example #31
0
def main:
	sensors()
	while True:
		# Read from ultrasonic data
		ultrasonic_reading = ReadChannel(ultrasonic_channel)
		ultrasonic_voltage = ConvertVolts(ultrasonic_reading, 2)
		# Decide if high or low
		highlow = ConvertHighLow(ultrasonic_voltage)
		print("-------------------------------")
		print("Voltage: {}").format(ultrasonic_voltage)
		print("Digital Value: {}").format(highlow)
		GPIO.output(output_channel, highlow)
		print("-------------------------------")
		print("Sent from output channel")
		print("-------------------------------")
		value_read = GPIO.input(input_channel)
		print("Value: {}").format(value_read)
		time.sleep(.01)
Example #32
0
    def getPhotoSensorData():
	data = 0;
	GPIO.setup(PHOTO_SENSOR_PIN, GPIO.OUT)
	GPIO.output(PHOTO_SENSOR_PIN, LOW)
	time.sleep(0.1)
	GPIO.setup(pin, GPIO.IN)
	while(GPIO.input(PHOTO_SENSOR_PIN) == GPIO.LOW):
		data += 1 # 
	return data
Example #33
0
#!/usr/bin/python

import RPI.GPIO as GPIO
import time
import BaseHTTPServer

# Make sure Pins Reads
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Setup pin 4 as ouput for sending the signal to the intercom and make it initially zero
INTERCOM_PIN = 4
GPIO.setup(INTERCOM_PIN, GPIO.OUT)
GPIO.output(INTERCOM_PIN, 0)

# Start the web server
WEB_SERVER_PORT = 8080
WEB_SERVER_HOST = "localhost"

class DoorHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(s):
        s.send_response(200)
        s.send_header("Content-type", "text/plain")
        s.end_headers()
        GPIO.output(INTERCOM_PIN, 1)
        time.sleep(2)
        GPIO.output(INTERCOM_PIN, 0)

server_class = BaseHTTPServer.HTTPServer
httpd = server_class((WEB_SERVER_HOST, WEB_SERVER_PORT), DoorHandler)
print time.asctime(), "Server Starts - %s:%s" % (WEB_SERVER_HOST, WEB_SERVER_PORT)
Example #34
0
def power_led(state):
    if state == 1:
        gpio.output(15,True)
    else:
        gpio.output(15,False)
Example #35
0
def processing_led(state):
    if state == 1:
        gpio.output(14,True)
    else:
        gpio.output(14,False)
Example #36
0
DC_PIN    = 5 

led = gaugette.ssd1306.SSD1306(reset_pin=RESET_PIN, dc_pin=DC_PIN)
led.begin()
led.clear_display()

offset = 0 # flips between 0 and 32 for double buffering

#text = "preparing camera ..."
#led.draw_text2(0,0,text,1)
#text = "(please hold)"
#led.draw_text2(0,9,text,1)
#led.display()


GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)


imgIndex=0

while True:

    text="Ready!"
    led.draw_text2(0,0,text,2)	   
    imgLabel = "%05d" % imgIndex
    imgName = "snap_"+imgLabel+".jpeg"
    if ( GPIO.input(25)== True):
        os.system('fswebcam '+imgName)
        imgIndex=imgIndex+1
	led.clear_display()
Example #37
0
import RPI.GPIO asGPIO
from urllib.request import urlopen
from bs4 import BeautifulSoup
GPIO.setmode(GPIO.BOARD)
//databox=urlopen(http://soramame.taiki.go.jp/DataList.php?MstCode=13102010).read()
databox=urlopen(http://soramame.taiki.go.jp/DataList.php?MstCode=24207510).read()

targetUrl="http://soramame.taiki.go.jp/"+htmldatabox.frameset.findAll("frame")[1]["src"]
databox2=urlopen(targetUrl).read()
htmldatabox2=BeautifulSoup(databox2,"html.parser")

yy=htmldatabox2.find("table").find("tr").find("td").find("table").findAdd("td")[0].get_text()
mm=htmldatabox2.find("table").find("tr").find("td").find("table").findAdd("td")[1].get_text()
dd=htmldatabox2.find("table").find("tr").find("td").find("table").findAdd("td")[2].get_text()
hh=htmldatabox2.find("table").find("tr").find("td").find("table").findAdd("td")[3].get_text()
no2=htmldatabox2.find("table").find("tr").find("td").find("table").findAdd("td")[6].get_text()

print("YYMMDDSSNO2:"+str(yy)+"-"+str(mm)+"/"+str(dd)+":"+str(hh)+">"str(no2)+"ppm")
if float(no2) <0.06:
	print ("No problem!")
else:
	print("Attention! Over limit NO2.Please do action !")
	//GPIO.setup(40,GPIO.OUT)
	//GPIO.output(40,0)
GPIO.cleanup()
Example #38
0
 def turnOn(pin):
     GPIO.output(pin, True)
Example #39
0
 def turnOff(pin):
     GPIO.output(pin, False)
Example #40
0
 def startMotor(pin):
     GPIO.output(pin, True)
Example #41
0
 def stopMotor(pin):
     GPIO.output(pin, False)
Example #42
0
def SwitchState(Stateu):
    global State
    State = Stateu
    GPIO.output(5,State)
Example #43
0
from flask import Flask, render_template
app = Flask(__name__,template_folder="www")
import RPI.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(5,GPIO.OUT)

State = False

def SwitchState(Stateu):
    global State
    State = Stateu
    GPIO.output(5,State)

@app.route('/')
def index():
    return render_template("index.html")

@app.route('/Output')
def Output():
    global State
    return str(State) + " :D"

@app.route('/Input/<Statuu>')
def Input(Statuu):
    global State
    SwitchState(Statuu)
    return str(State) + "   " + str(Statuu)

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0',port=80)
Example #44
0
    else:
        client.send('Piabetes is back online',totext)
    os.remove(local_dir+'Reboot.nt')
    print timestamp()+'Reboot file detected | administering notification to '+totext

try:
    import RPI.GPIO as gpio
except ImportError:
    print 'No GPIO Found'
    print 'Indicator LEDs will be unavailable'
    gpio_avail = False
else:
    print 'GPIO imported'
    print 'Indicator LEDs are now running (if they\'re plugged in)'
    gpio_avail = True
    gpio.setup(14,gpio.OUT)
    gpio.setup(15,gpio.OUT)
#
#
#
#
#
#GPIO Light Definitions
def processing_led(state):
    if state == 1:
        gpio.output(14,True)
    else:
        gpio.output(14,False)

def power_led(state):
    if state == 1:
Example #45
0
PHOTO_SENSOR_PIN = 22	    # Pghotoresistor 
HUMIDITY_TEMP_PIN = 27	    # DHT22 humidity-temerature sensor
MOTOR_PIN_OPEN = 12         # jaloise operation motor`s GPIO pin
MOTOR_PIN_CLOSE = 16        # jaloise operation motor`s GPIO pinFAN_PIN = 16                
IRL_PIN = 11                # pin to turn on infrared lamp
WATER_PUMP_PIN = 13         # pin to send signal to a water pump

PHOTO_MAX = 50000           # max allowable level of illumination
PHOTO_MIN = 40000     
TEMP_MAX = 25               #allowable level of temperature
TEMP_MIN = 22
HUMIDITY_MAX = 80           #allowable level of humidity
HUMIDITY_MIN = 70
        
GPIO.setmode(GPIO.BOARD)

#---------------------Class Photo Sensor------------------------
class PhotoSensor:
    # Get data from photo sensor
    def getPhotoSensorData():
	data = 0;
	GPIO.setup(PHOTO_SENSOR_PIN, GPIO.OUT)
	GPIO.output(PHOTO_SENSOR_PIN, LOW)
	time.sleep(0.1)
	GPIO.setup(pin, GPIO.IN)
	while(GPIO.input(PHOTO_SENSOR_PIN) == GPIO.LOW):
		data += 1 # 
	return data

#--------------------Class Temperature and Humidity sensor------
#!/usr/bin/env python 
import os
import RPI.GPIO as GPIO
from gps import *
from time import *
import time
import threading
GPIO.setmode(GPIO.BOARD)
GPIO.setup(24, GPIO.OUT)#GPS LOCK LED
gpsd = None #setting the global variable
class GpsPoller(threading.Thread):
        def __init__(self):
                threading.Thread.__init__(self)
        global gpsd #bring it in scope
        gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
        self.current_value = None
        self.running = True #setting the thread running to true
        def run(self):
                global gpsd
        while gpsp.running:
                gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
	if __name__ == '__main__':
        	gpsp = GpsPoller() # create the thread
        try:
                gpsp.start() # start it up
                while True:
                #It may take a second or two to get good data
                        print ' GPS mode:'
                        print '----------------------------------------'
                        print 'mode        ' , gpsd.fix.mode # all values greather than 1 is a GPS fix.
                while True:
Example #47
0
import RPI.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT)
print "Backlight on"
GPIO.output(17,GPIO.HIGH)
Example #48
0
# Input Polling 
# Python code checks the current value of a GPIO input pin at a regular interval.
# When the GPIO changes value, this means that the button has been pressed.



import RPI.GPIO as GPIO
import time 

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.output(18, GPIO.LOW)

try:
	while True:
		if (GPIO.input(24) == GPIO.LOW):
			print ('Back Door')
			GPIO.output(18, GPIO.HIGH)
		elif (GPIO.input(25) == GPIO.LOW):
			print ('Front Door')
			GPIO.output(18, GPIO.HIGH)
		else:
			GPIO.output(18, GPIO.LOW)
		time.sleep(0.1)
except KeyboardInterrupt:
	GPIO.cleanup()
print('End of Test')
Example #49
0
    def startMotor(pin):
	GPIO.setup(pin, GPIO.OUT)
	GPIO.output(pin, HIGH)
Example #50
0
    def stopMotor(pin):
    	GPIO.setup(pin, GPIO.OUT)
	GPIO.output(pin, LOW)
Example #51
0
import RPI.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
led = int(7)
powerinput = int(11)
status = int(1)
GPIO.setup(led, GPIO.OUT)
GPIO.setup(11, GPIO.IN)
while time:
    if GPIO.input(11) == False:
        if status == 0
            GPIO.output(7, False)
            print'off'
            status = 1
            time.sleep(0.3)
            continue
        if status == 1
            GPIO.output(7, true)
            print 'on'
            status = 0
            time.sleep(0.3)
            continue
                    
Example #52
0
from flask import Flask, render_template
import datetime
import RPI.GPIO as GPIO
app = Flask(__name__)

GPIO.setmode(GPIO.BCM)

@app.route("/")
def hello():
  now = datetime.datetime.now()
  timeString = now.strftime("%Y - %m - %d %H:%M")
  templateData = {
   'title' : 'Return page from Raspberry Pi Server', 
   'time' : timeString
}
  
  return render_template('main.html', **templateData)



@app.route("/readPin/<pin>")
def readPin(pin):
	try:
		GPIO.setup(int(pin),GPIO.IN)
		if GPIO.setup(int(pin)) == True:
        		response = "Pin number " + pin + " is high !"
                else :
			response = "Pin number " + pin + " is low !"
		except :  
			response = "There was an error reading Pin " + pin + " . "