В момента ресурсът е наличен само на английски

Python LED control - explanation to the challenges Pro Preview

Here we have detailed explaination what we expect from you. Bonus: how to do copy-paste within nano.

Необходимо е да се абонирате за FLLCasts.com, за да достъпите това видео

Абонирай се

  • #832
  • 09 Apr 2018

Read carefully all the python code in ledPulseDemo.py

The idea is that you must understand for yourself what is the result of each line of code in the file. There are comments (explanations) after some of the lines starting with the hash symbol: "#".

 

Create a program to greet you by your name

Create a new file named greeting.py and type something with the print() function.

nano greeting.py

 

Create a program to start the lights with brightness equal to your age.

Here things start to get serious. The challenge is to create the shortest possible file, so copy only what is needed from the demo file. Yes, you can copy part of the original demo file, we don't expect you to type all the code. A programmer thinks more than he types.

Name your program ledBrightness.py.

 

Don't forget to housekeep you program

Try to start that program a few times. The LED might not turn off at some point. That is because you did not close your GPIO bus at the end of the program.

Always call 

GPIO.cleanup()

in the end of your programs.

 

Change the program to start the lights with brightness three times your age.

After you have made the diode blink, practice some variable assignments and calculations. Something like

age = 32

max_light = age * 3

front_lights.start(max_light)

 

How to do copy-paste of line within nano editor

Feel free to use the external editor and to copy and paste away. But if some day you work with the nano alone, you must remember that Ctrl+K cuts text. Then Ctrl+U pastes it.

So, do Ctrl+K on a line, then immediately Ctrl+U and the line will be restored. Now you can Ctrl+U on any other line, unlimited ammounto of times and you will have copies of your line. 
Comes handy in the next challenge.

 

Create a program that blinks the LED as letter "R" in morse code

A Morse Code is something from the past that is not going to be used in practice anymore. It was a system for transmistting messages across large distances in the sea with radio waves. It was largely used in the past century and you could hear stories about it from grown-ups. Ask your parents, it could be fun.

The letters in morse code are encrypted with dashes and dots. One dash is three times longer than a dot and the pause between dashes and dots in a letter is as long as a dash.

If you are interested to transmit more than one letter, the pause between letters must be three dots long, and the pause between words must be sevent dots long.

So your task is to make the LED blink in morse code and to transmit letter "R".

morse code

Курсове и занятия включващи този Урок

Този Урок е използван в следните курсове и занятия.

Image for Perfect STEM course. Module 1 - Smart Car with Raspberry PI
  • 118
  • 42:47
  • 136