Skip to content

Instantly share code, notes, and snippets.

@kcranley1
Last active August 29, 2015 13:57
Show Gist options
  • Save kcranley1/9761331 to your computer and use it in GitHub Desktop.
Save kcranley1/9761331 to your computer and use it in GitHub Desktop.
This version uses picamera to record video!
#! /usr/bin/env python
# KCtest3.py - Records a video using picamera
import time
import os.path
import sys
import pygame
import pygame.mixer
import picamera
import pibot
MUSIC_VOLUME = 0.5
TEST_TIME = 10.0
scriptPath = os.path.dirname( __file__ )
# Load test result sounds
pygame.init()
pygame.mixer.init()
time.sleep(1)
pygame.mixer.music.load( scriptPath + "musical073.mp3" )
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16)
pygame.mixer.music.play()
time.sleep(7)
pygame.mixer.music.load( scriptPath + "drum_roll.mp3" )
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16)
pygame.mixer.music.play()
time.sleep(5)
camera = picamera.PiCamera()
camera.resolution = (640, 480)
camera.start_preview()
camera.start_recording('foo.h264')
camera.hflip = True
camera.vflip = True
# Connect to the PiBot
bot = pibot.PiBot()
for i in range (300):
dist = bot.getUltrasonicDistance()
time.sleep(0.1)
print "Distance = ",str(dist[0]).replace('[',' ').replace(']',' '),"cm"
if dist[0] < 15:
bot.setMotorSpeeds(-192, 192)
for pixelIdx in range(bot.NUM_NEO_PIXELS ):
bot.setNeoPixelColour(pixelIdx, 128, 0, 0)
else:
bot.setMotorSpeeds(192, 192)
for pixelIdx in range(bot.NUM_NEO_PIXELS):
bot.setNeoPixelColour(pixelIdx, 0, 128, 0)
camera.stop_recording()
camera.stop_preview()
camera.close()
for pixelIdx in range(bot.NUM_NEO_PIXELS, -1, -1):
bot.setNeoPixelColour(pixelIdx, 0, 0, 128)
time.sleep(0.2)
del bot
time.sleep(1)
pygame.mixer.music.load(scriptPath + "failure.mp3")
pygame.mixer.music.set_volume(MUSIC_VOLUME * 4)
pygame.mixer.music.play()
time.sleep(3)
pygame.mixer.music.load( scriptPath + "success.mp3" )
pygame.mixer.music.set_volume( MUSIC_VOLUME )
pygame.mixer.music.play()
time.sleep(1)
pygame.mixer.music.load( scriptPath + "animals023.mp3" )
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16 )
pygame.mixer.music.play()
time.sleep(3)
pygame.mixer.music.load( scriptPath + "animals023.mp3" )
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16 )
pygame.mixer.music.play()
time.sleep(3)
while pygame.mixer.music.get_busy():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment