Пример #1
0
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
"""
import _wingpio as gpio
import time

led_pin = 5
pinValue = gpio.HIGH

gpio.setup(led_pin, gpio.OUT, gpio.PUD_OFF, gpio.HIGH)

while True:
    if pinValue == gpio.HIGH:
        pinValue = gpio.LOW
        gpio.output(led_pin, pinValue)
    else:
        pinValue = gpio.HIGH
        gpio.output(led_pin, pinValue)

    time.sleep(0.5)

gpio.cleanup()
Пример #2
0
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
"""
import http.server
import socketserver
import _wingpio as gpio

led_pin = 5
led_status = gpio.HIGH

gpio.setup(led_pin, gpio.OUT, gpio.PUD_OFF, led_status)

class BlinkyRequestHandler(http.server.BaseHTTPRequestHandler):
    def do_HEAD(self):
        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.end_headers()
    def do_GET(self):
        global led_status
        if led_status == gpio.LOW:
            self.wfile.write(b"Setting pin to HIGH")
            print('Setting pin to HIGH')
            led_status = gpio.HIGH
        else:
            self.wfile.write(b"Setting pin to LOW")
            print('Setting pin to LOW')
Пример #3
0
""" Copyright (c) Microsoft. All rights reserved."""

import http.server
import socketserver
import _wingpio as gpio

led_pin = 5
led_status = gpio.HIGH

gpio.setup(led_pin, gpio.OUT, gpio.PUD_OFF, led_status)


class BlinkyRequestHandler(http.server.BaseHTTPRequestHandler):
    def do_HEAD(self):
        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.end_headers()

    def do_GET(self):
        global led_status
        if led_status == gpio.LOW:
            self.wfile.write(b"Setting pin to HIGH")
            print('Setting pin to HIGH')
            led_status = gpio.HIGH
        else:
            self.wfile.write(b"Setting pin to LOW")
            print('Setting pin to LOW')
            led_status = gpio.LOW
        gpio.output(led_pin, led_status)

import _wingpio as gpio  # The GPIO library
import time  # Time functions

BLINK_TIME = 30.0  # blink for 30 seconds
GPIO_PIN = 4  # GPIO4 (not pin #4)

pin_val = gpio.HIGH  # Store pin value (high/low)
elapsed_time = 0  # Store time in seconds

# Setup the GPIO
gpio.setup(GPIO_PIN, gpio.OUT, gpio.PUD_OFF, gpio.HIGH)

# Run the blink series for
while (elapsed_time < BLINK_TIME):
    # If LED is on, turn it off
    if pin_val == gpio.HIGH:
        pin_val = gpio.LOW
        gpio.output(GPIO_PIN, pin_val)
    # else, turn it on
    else:
        pin_val = gpio.HIGH
        gpio.output(GPIO_PIN, pin_val)

    # Sleep for 1/2 second
    time.sleep(1)
    elapsed_time = elapsed_time + 1

# Close down and cleanup the GPIO
gpio.cleanup()
Пример #5
0
import _wingpio as gpio

led_pin = 6;
button_pin = 5;

ledPinValue = gpio.HIGH;

gpio.setup(button_pin, gpio.IN, gpio.PUD_UP, None);
gpio.setup(led_pin, gpio.OUT);
print("GPIO pins initialized correctly.")

gpio.output(led_pin, gpio.HIGH);

def buttonPin_ValueChanged(sender):
    if gpio.input(button_pin):
        if ledPinValue == gpio.HIGH:
            ledPinValue = gpio.LOW;
        else:
            ledPinValue = gpio.HIGH;

        print("Button released")
    else:
        print("Button Pressed")

gpio.add_event_detect(button_pin, gpio.BOTH, callback=buttonPin_ValueChanged, bouncetime=50);
print("GPIO event registered")
                gpio.output(DND, gpio.HIGH)
            elif option == b"bbl":
                states[4] = "checked"
                gpio.output(BBL, gpio.HIGH)
            elif option == b"lunch":
                states[5] = "checked"
                gpio.output(LUNCH, gpio.HIGH)
            elif option == b"gftd":
                states[6] = "checked"
                gpio.output(GFTD, gpio.HIGH)
        print("Setting states: {0}".format(",".join(states)))
        self.wfile.write(
            HTML.format(states[0], states[1], states[2], states[3], states[4],
                        states[5], states[6]).encode())


# Initialize the pins, set to LOW (OFF)
for i in LED_PINS:
    gpio.setup(i, gpio.OUT, gpio.PUD_OFF, gpio.HIGH)
    gpio.output(i, gpio.LOW)
gpio.setup(SERVO_PIN, gpio.OUT, gpio.PUD_OFF, gpio.HIGH)
gpio.output(SERVO_PIN, gpio.LOW)

# default is "Available"
gpio.output(AVAIL, gpio.HIGH)

# Run the http server indefinitely
httpd = http.server.HTTPServer(("", 8081), RequestHandler)
print('Started web server on port %d' % httpd.server_address[1])
httpd.serve_forever()
from urllib.parse import parse_qs
from http.server import BaseHTTPRequestHandler
from time import sleep
# for sched
import sched, time
from datetime import datetime
# for Azure queue
import postazq
# for weather factor
import weather
# for gpio control
import _wingpio as gpio

valve_pin = 5
moisture_pin = 6
gpio.setup(valve_pin, gpio.OUT, gpio.PUD_OFF, gpio.HIGH)
gpio.setup(moisture_pin, gpio.IN, gpio.PUD_OFF)

# Globals for state
gPostVars = None

# Initialize an empty schedule with 10 (0 thru 9) events
# I *want* to save and read it from disk but cannot access it in Win10 IoT on RPi2
schedule = {}
for key in range(10):
  schedule[key] = {"timeofday":"XX:XX","dayofweek":"X","duration":"X"}


# create the global table for the page
table = "<TABLE border=1><TR><TD>Event</TD><TD>Day of week</TD><TD>Time of day</TD><TD>Duration</TD></TR>"
for key in schedule:
Пример #8
0
 def __init__(self, p1, p2, p3, p4):
    self.pin1 = p1
    self.pin2 = p2
    self.pin3 = p3
    self.pin4 = p4
    if sys.platform == "win32":
       gpio.setup(self.pin1, gpio.OUT, gpio.PUD_OFF, gpio.LOW)
       gpio.setup(self.pin2, gpio.OUT, gpio.PUD_OFF, gpio.LOW)
       gpio.setup(self.pin3, gpio.OUT, gpio.PUD_OFF, gpio.LOW)
       gpio.setup(self.pin4, gpio.OUT, gpio.PUD_OFF, gpio.LOW)
    elif sys.platform == "linux":
       gpio.setup(self.pin1, gpio.OUT)
       gpio.setup(self.pin2, gpio.OUT)
       gpio.setup(self.pin3, gpio.OUT)
       gpio.setup(self.pin4, gpio.OUT)
       self.setStep(0, 0, 0, 0)
    Stepper.numSteppers += 1