This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hey all,
I've been doing a little project with my raspberry pi recently where I am trying to write a code that will take a user input, sort it, reject bad inputs, and then eventually it outputs the users input as morse code using an LED.
One of the ideas that I had while writing this code was to create a "library" of all the different morse codes for every letter and punctuation and just turn that into a class and import it into the main program so that it doesn't take up a lot of space. In this "library" I will have the written out code that will control the GPIO to output the morse code on the LED.
So from my basic understanding of classes, I think I will have to import the GPIO class as well as the datetime class (to tell the program to sleep and thus generate all the shorts and longs on the LED) into this "library" class. Is that possible/okay to do?
And then I have also been running into an error where when I try to import my "library" class into my main program, it gives me an attribute error on functions that I know are in my class. So I'm wondering if there is some sort of syntax error that I made and because of that my program sees my class as being empty?
Here's what I have so far:
import RPi.GPIO as GPIO
from datetime import time
class MDef:
def __init__(self, color)
self.color = color
def A(self, color)
GPIO.output(color,0)
time.sleep(0.2)
...
(I didn't fill out all of the code, but it's basically just repeating the GPIO/sleep cycle over and over)
The color input that I have is to allow the user to select whether they want the RGB LED that I'm using to output the morse code in either of those three colors.
Any help would be appreciated! Thanks everyone.
Subreddit
Post Details
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...