SHARE
TWEET

Untitled

a guest Dec 13th, 2016 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import email
  3. import smtplib
  4. import email.utils
  5. import os
  6. import picamera
  7.  
  8. import RPi.GPIO as GPIO
  9. from time import sleep
  10. import sys, pygame, time
  11. from picamera import PiCamera
  12.  
  13. camera = PiCamera()
  14.  
  15. from email.mime.multipart import MIMEMultipart
  16. from email.mime.text import MIMEText
  17. from email.mime.base import MIMEBase
  18. from email.mime.image import MIMEImage
  19. from email import encoders
  20.  
  21. USERNAME = "birzhan7777@gmail.com"
  22. PASSWORD = "password"
  23. MAILTO = "bio.serikov@gmail.com"
  24.  
  25. """
  26. def takePhoto(name):
  27.     camera.start_preview()
  28.     camera.capture(name)
  29. """
  30.  
  31. def recordVideo(vakit):
  32.     camera.image_effect = 'colorswap'
  33.     camera.annotate_text = "Hello Almas"
  34.     camera.resolution = (600, 400)
  35.     camera.framerate = 10
  36.     place = "/home/pi/Desktop/"
  37.     VideoName = str(random.randint(1, 1000000))
  38.     VideoName += ".h264"
  39.     place += VideoName
  40.     camera.start_preview()
  41.     camera.start_recording(place)
  42.     time.sleep(vakit)
  43.     camera.stop_recording()
  44.     camera.stop_preview()
  45.     return VideoName
  46.  
  47. def get(x):
  48.     k = 0
  49.     if pos[1] >= height / 2:
  50.         k = 2
  51.     for i in range(2):
  52.         if i * width / 2 <= pos[0] and pos[0] <= (i + 1) * width / 2:
  53.             return i + k + 1
  54.  
  55. def sendPhoto(name):
  56.     img_data = open(name, 'rb').read()
  57.     msg = MIMEMultipart()
  58.     msg['Subject'] = 'Subject'
  59.     msg['From'] = USERNAME
  60.     msg['To'] = MAILTO
  61.     text = MIMEText("test")
  62.     msg.attach(text)
  63.     image = MIMEImage(img_data, name = os.path.basename(name))
  64.     msg.attach(image)
  65.     s = smtplib.SMTP('smtp.gmail.com:587')
  66.     s.ehlo()
  67.     s.starttls()
  68.     s.ehlo()
  69.     s.login(USERNAME, PASSWORD)
  70.     s.sendmail(USERNAME, MAILTO, msg.as_string())
  71.     s.quit()
  72.  
  73. def SendVideo(name):   
  74.     msg = MIMEMultipart()
  75.     msg['Subject'] = 'Subject'
  76.     msg['From'] = USERNAME
  77.     msg['To'] = MAILTO
  78.     attachment = open(name, "rb")
  79.     part = MIMEBase('application', 'octet-stream')
  80.     part.set_payload(attachment.read())
  81.     encoders.encode_base64(part)
  82.     part.add_header('Content-Dispoistion', 'attachment; filename = "%s"' % os.path.basename(name)) 
  83.     msg.attach(part)   
  84.     s = smtplib.SMTP('smtp.gmail.com:587')
  85.     s.ehlo()
  86.     s.starttls()
  87.     s.ehlo()
  88.     s.login(USERNAME, PASSWORD)
  89.     s.sendmail(USERNAME, MAILTO, msg.as_string())
  90.     s.quit()
  91. def rotate():
  92.     GPIO.output(13, GPIO.HIGH)
  93.     GPIO.output(19, GPIO.LOW)
  94.     GPIO.output(26, GPIO.HIGH)
  95.     Motor1A.ChangeDutyCycle(100)
  96.     Motor1B.ChangeDutyCycle(0)
  97.     GPIO.output(16, GPIO.LOW)
  98.     GPIO.output(20, GPIO.HIGH)
  99.     GPIO.output(21, GPIO.HIGH)
  100.     Motor2A.ChangeDutyCycle(0)
  101.     Motor2B.ChangeDutyCycle(100)
  102.    
  103. def Video_sdelai():
  104.     rotate()
  105.  
  106. #SendVideo(recordVideo(15))
  107.  
  108. GPIO.setmode(GPIO.BCM)
  109. pygame.init()
  110. size = width, height = 300, 200
  111. prev_time = time.time()
  112.  
  113. GPIO.setup(13, GPIO.OUT)
  114. GPIO.setup(19, GPIO.OUT)
  115. GPIO.setup(26, GPIO.OUT)
  116.  
  117. GPIO.setup(16, GPIO.OUT)
  118. GPIO.setup(20, GPIO.OUT)
  119. GPIO.setup(21, GPIO.OUT)
  120.  
  121. Motor1A = GPIO.PWM(13, 10)
  122. Motor1B = GPIO.PWM(19, 10)
  123. Motor1E = GPIO.PWM(26, 10)
  124.  
  125. Motor2A = GPIO.PWM(16, 10)
  126. Motor2B = GPIO.PWM(20, 10)
  127. Motor2E = GPIO.PWM(21, 10)
  128.  
  129. speed = 0
  130.  
  131. Motor1A.start(0)
  132. Motor1B.start(0)
  133. Motor1E.start(100)
  134.  
  135. Motor2A.start(0)
  136. Motor2B.start(0)
  137. Motor2E.start(100)
  138.  
  139. last = [0, 0]
  140. end = 0
  141.  
  142. screen = pygame.display.set_mode(size)
  143.  
  144. positions = []
  145. side = 0
  146.  
  147. while end == 0:
  148.     now = time.time()
  149.     for event in pygame.event.get():
  150.         if event.type == pygame.QUIT:
  151.             GPIO.cleanup()
  152.             pygame.quit()
  153.             sys.exit()
  154.         if event.type == pygame.MOUSEBUTTONDOWN:
  155.             pos = pygame.mouse.get_pos()
  156.             now = time.time()
  157.             positions.append(pos)
  158.         if event.type == pygame.MOUSEBUTTONUP:
  159.             pos = pygame.mouse.get_pos()
  160.             now = time.time()
  161.             positions.append(pos)
  162.             if now - prev_time >= 1:
  163.                 positions = []
  164.                 prev_time = now
  165.                 last = pos
  166.                 side = get(last)
  167.                 if side == 1:
  168.                     Video_sdelai()
  169.                     print("Turn around and record video")
  170.                 elif side == 2:
  171.                     print("Turn around and make 4 photos")
  172.                 elif side == 3:
  173.                     print("U-turn")
  174.                 else:
  175.                     print("make circle")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top