Saturday, 5 January 2013

Another new year, another post, This time to test the nice Code formatting script SyntaxHighlighter
and to show off the code I am playing with on the Raspberry pi, plus the add-on board the Berryclip, gifted to me by my long suffering friend +Carl Hughes.

Im attempting to make a python script that will flash or buzz morse code generated from text  entered by the user. 

Sample code to make the BerryClip flash Led1 the letter A in Morse code, to sound the buzzer you can use gpio pin (8).

#!/usr/bin/python

# Import required libraries
import RPi.GPIO as GPIO
import time

# Tell GPIO library to use GPIO references
GPIO.setmode(GPIO.BCM)
# List of LED GPIO numbers
LedSeq = [4,17,22,10,9,11]

# Set up the GPIO pins as outputs and set False
for x in range(6):
  GPIO.setup(LedSeq[x], GPIO.OUT)
  GPIO.output(LedSeq[x], False)
# Enable Buzzer
GPIO.setup(8, GPIO.OUT)
GPIO.output(8, False)

# Morse code 
# A
GPIO.output(LedSeq[0], True) #Start Led1
GPIO.output(8, True) #Start Buzzer
time.sleep(.25) #duration
GPIO.output(LedSeq[0], False) # Stop Led1
GPIO.output(8, False) # Stop Buzzer
time.sleep(.15)
GPIO.output(LedSeq[0], True)
GPIO.output(8, True)
time.sleep(.5)
GPIO.output(LedSeq[0], False)
GPIO.output(8, False)
time.sleep(.15)

# Reset GPIO settings
GPIO.cleanup()

No comments:

Post a Comment