0

I'm trying to get started with my Raspberry Pi pico H, and I thought of a cool little project to translate text into morse code using the onboard LED to flash as dots and dashes, but to do that I need to turn the LED off at specific intervals.

I made this program to flash the LED on and off infinitely:

from machine import Pin
import time
onboardLED = Pin(25, Pin.OUT)
def LED1():
    {
        onboardLED.value(1)
    }

def LED0():
    {
        onboardLED.value(0)
    }

on = LED1
off = LED0


x = 1

while x < 2:
    on()
    time.sleep(0.1)
    off()
    time.sleep(0.1)

which works as I expected. Then, I tried to introduce 2 new functions, one for a dot and one for a dash:

from machine import Pin
import time
onboardLED = Pin(25, Pin.OUT)
def LED1():
    {
        onboardLED.value(1)
    }

def LED0():
    {
        onboardLED.value(0)
    }

on = LED1
off = LED0


def DOT():
    {
        on()
        time.sleep(1)
        off
        time.sleep(1)
    }

def DASH():
    {
        on()
        time.sleep(2.5)
        off()
        time.sleep(1)
    }
    
dot = DOT
dash = DASH


But I keep getting a syntax error for line 21, being the first time.sleep(1) within defining DOT as a function, which I assume means that there's an error using the time.sleep function within defining another function?

  • 3
    Python… doesn’t use braces for functions? The first case happens to “work” because it’s a set display with one element. – Davis Herring Dec 04 '22 at 00:37
  • I think you need to start with some basic tutorials to become more familiar with the language. There are some examples in the micropython documentation, and really just about any basic Python tutorial would also be relevant (note that there are some differences between python and micropython, but for a basic introduction they are very similar). – larsks Dec 04 '22 at 00:58
  • AH, I did some pythonbasics about 2 years ago and since then I did some slight programming in C#, I think the two have been merged in the time since I did either. THanks for the help guys, I've gotten the program working now! – SleepyTheSloth Dec 04 '22 at 01:10
  • Try the remove the braces and clean the code. For example calling the dot and dash functions use parentesis always.And why you are saving the functions in a variable?, if thats functions is not return anything. I hope helps you. – LordPaella Dec 07 '22 at 09:13

0 Answers0