Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

4
Need help writing a class
Post Body

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.

Author
Account Strength
90%
Account Age
10 years
Verified Email
Yes
Verified Flair
No
Total Karma
3,777
Link Karma
503
Comment Karma
3,241
Profile updated: 1 week ago
Posts updated: 1 week ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
8 years ago