示例#1
0
import BaseHTTPServer, SimpleHTTPServer
import ssl
import json
import re
import urllib2
import sys

from BreakfastSerial import Arduino, Led, Servo

import BreakfastSerial
FILENAME = "keys.json"
board = Arduino()
servo = Servo(board, 10)
leds = {'connected': Led(board, 5), 'disconnected': Led(board, 4),
        'locked': Led(board, 6), 'unlocked': Led(board, 7)}
is_locked = False

class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-Type', 'application/json')
        self.end_headers()

        path = self.path.split("?", 1)
        path_no_params = path[0]
        path = path[1] if len(path) > 1 else ""
        query = self.process_params(path)

        if path_no_params == '/lock':
            self.wfile.write(json.dumps(self.do_lock(query)))
        elif path_no_params == '/unlock':
import tensorflow as tf
import tflearn
from BreakfastSerial import Arduino, Servo
from time import sleep
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
import numpy as np
from PIL import Image
import cv2
import imutils

# global variables
bg = None
board = Arduino("/dev/ttyACM0")
servol = Servo(board, "8")
servor = Servo(board, "9")
servom = Servo(board, "10")
servoi = Servo(board, "11")
servot = Servo(board, "12")


def resizeImage(imageName):
    basewidth = 100
    img = Image.open(imageName)
    wpercent = (basewidth / float(img.size[0]))
    hsize = int((float(img.size[1]) * float(wpercent)))
    img = img.resize((basewidth, hsize), Image.ANTIALIAS)
    img.save(imageName)

示例#3
0
#! /usr/bin/env python
"""
This is an example that demonstrates how to use a
servo with BreakfastSerial. It assumes you have a 
servo wired up to pin 10.
"""
from BreakfastSerial import Arduino, Servo
from time import sleep

board = Arduino()
servo = Servo(board,10)

servo.set_position(180)
sleep(2)
servo.move(-135)
sleep(2)
servo.center()
sleep(2)
servo.reset()

# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()
示例#4
0
import code
code.InteractiveConsole(locals=globals()).interact()

########NEW FILE########
__FILENAME__ = servo
#! /usr/bin/env python
"""
This is an example that demonstrates how to use a
servo with BreakfastSerial. It assumes you have a 
servo wired up to pin 10.
"""
from BreakfastSerial import Arduino, Servo
from time import sleep

board = Arduino()
servo = Servo(board, 10)

servo.set_position(180)
sleep(2)
servo.move(-135)
sleep(2)
servo.center()
sleep(2)
servo.reset()

# Run an interactive shell so you can play (not required)
import code
code.InteractiveConsole(locals=globals()).interact()

########NEW FILE########