def data_from_light_sensor(): # create a list of binary data data = [] # GPIO pin set up GPIO.setup(light_clk, GPIO.OUT) GPIO.setup(light_cs, GPIO.OUT) GPIO.setup(light_pin, GPIO.IN) # Set ligth_cs to be high to start up light sensor GPIO.output(light_cs, GPIO.HIGH) # Give a time for light sensor to be stable time.sleep(0.5) # Collecting data for j in range(0,1): # Set light_cs to be low to start collecting data GPIO.output(light_cs, GPIO.LOW) for i in range(0,16): time.sleep(0.1) GPIO.output(light_clk, GPIO.LOW) time.sleep(0.1) GPIO.output(light_clk, GPIO.HIGH) # put data into list data.insert(i,GPIO.input(light_pin)) # Set light_cs back to high again GPIO.output(light_cs, GPIO.HIGH) # the first 5 bits and the last 5 bits are useless del data[12:16] del data[0:4] # Convert data to decimal result = convert_to_tens(data) return result
import PRi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(1, GPIO.IN) GPIO.setup(2, GPIO.IN) GPIO.setup(3, GPIO.IN) GPIO.setup(4, GPIO.IN) GPIO.setup(5, GPIO.IN) GPIO.setup(6, GPIO.IN) GPIO.setup(7, GPIO.IN) GPIO.setup(8, GPIO.IN) GPIO.setup(9, GPIO.IN) GPIO.setup(10, GPIO.IN) GPIO.setup(11, GPIO.IN) GPIO.setup(12, GPIO.IN) GPIO.setup(13, GPIO.IN) GPIO.setup(14, GPIO.IN) GPIO.setup(15, GPIO.IN) GPIO.setup(16, GPIO.IN) GPIO.setup(17, GPIO.IN) GPIO.setup(18, GPIO.IN) GPIO.setup(19, GPIO.IN) GPIO.setup(20, GPIO.IN) GPIO.setup(21, GPIO.IN) GPIO.setup(22, GPIO.IN) GPIO.setup(23, GPIO.IN) GPIO.setup(24, GPIO.IN) GPIO.setup(25, GPIO.IN) GPIO.setup(26, GPIO.IN) GPIO.setup(27, GPIO.IN)
def __init__(self, pin, hz): GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.OUT) servo = GPIO.PWM(pin, hz) servo.start(0) self.StartUp()
import time import PRi.GPIO as GPIO import cv2 import smtplib from email.MIMEText import MIMEText from email.Header import Header INTAVAL = 50 SLEEPTIME = 5 SENSOR_PIN = 18 c = cv2.VideoCapture(0) i = 0 GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(SENSOR_PIN,GPIO.IN) def create_msg(from_address,to_address,subjecct,body,encode): meg = MIMEText(body,`plain`,encode) msg[`Subject`] = Header(subject,encode) msg[`from`] = from_address msg[`to`] = to_adrress return msg def send_by_local(from_address,to_address,msg): s = smtplib.SMTP() s.connect() s.sendmail(from_addess,[to_address],msg,as_string()) s.close() st = time.time() - INTAVAL
import PRi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.setup(11, GPIO.OUT) GPIO.setup(13, GPIO.OUT) for x in range(0, 7): GPIO.output(7, True) time.sleep(.5) GPIO.output(7, False) GPIO.output(11, True) time.sleep(.5) GPIO.output(11, False) GPIO.output(13, True) time.sleep(.5) GPIO.output(13, False) GPIO.cleanup()
import random import os import time import PRi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(7,GPIO.IN) GPIO.setup(8,GPIO.IN) GPIO.setup(9,GPIO.IN) a=0 def preguntas(): if(a== 1): print"Que tipo de pokemon es gil?" print"\n A) Fuego" print"\n B) Agua " print"\n C) Electrico" if(a== 2): print"A que animal del artico te recuerda Geras?" print"\n A) Foca" print"\n B) Pinguino" print"\n C) Oso polar" if(a== 3): print"Como se llama el robot mas poderoso de inteli?" print"\n A) RAD" print"\n B) Dummy bot" print"\n C) Royito" if(a== 4): print"Cuanto es 2+2?"