Skip to content

Instantly share code, notes, and snippets.

@kcranley1
Last active August 29, 2015 13:57
Show Gist options
  • Save kcranley1/9531810 to your computer and use it in GitHub Desktop.
Save kcranley1/9531810 to your computer and use it in GitHub Desktop.
A version of test_pibot_hardware.py - under construction!. Hoping to develop it to use the ultrasonic distance detector to stay out of trouble!
#! /usr/bin/env python
# KCtest1.py
import time
import os.path
import sys
import pygame
import pygame.mixer
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)
# 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)
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