Reputation: 9
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?
Upvotes: 0
Views: 148