Solution to the challenges. Teachers note Pro Preview

Example code that solves the challenges.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #836
  • 09 Apr 2018

Create a program to greet you by your name

print("Hello, mr/mrs Teacher")

 

 

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

from time import sleep                                          # we need sleep function from time library
import RPi.GPIO as GPIO                                         # GPIO library to control pins

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)                                          # BCM means we will use GPIO numbers, not pin numbers
frontLightsPin = 18                                             # GPIO 18
frequency = 50

frequency = 50 
GPIO.setup(frontLightsPin, GPIO.OUT)                            # set GPIO 18 in output mode, the led is there

front_lights = GPIO.PWM(frontLightsPin, frequency)              # PWM = pulse width modulation with 50Hz (blinks per second)


max_light = 32

front_lights.start(max_light)
sleep(0.200)
front_lights.stop()

GPIO.cleanup()

 

 

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

from time import sleep                                          # we need sleep function from time library
import RPi.GPIO as GPIO                                         # GPIO library to control pins

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)                                          # BCM means we will use GPIO numbers, not pin numbers
frontLightsPin = 18                                             # GPIO 18

frequency = 50 GPIO.setup(frontLightsPin, GPIO.OUT)                            # set GPIO 18 in output mode, the led is there

front_lights = GPIO.PWM(frontLightsPin, frequency)              # PWM = pulse width modulation with 50Hz (blinks per second)

age = 32
max_light = age * 3 

front_lights.start(max_light)
sleep(0.200)                                                    # dot
front_lights.stop()

GPIO.cleanup()

 

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

 

from time import sleep                                          # we need sleep function from time library
import RPi.GPIO as GPIO                                         # GPIO library to control pins

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)                                          # BCM means we will use GPIO numbers, not pin numbers
frontLightsPin = 18                                             # GPIO 18

frequency = 50 GPIO.setup(frontLightsPin, GPIO.OUT)                            # set GPIO 18 in output mode, the led is there

front_lights = GPIO.PWM(frontLightsPin, frequency)              # PWM = pulse width modulation with 50Hz (blinks per second)

age = 32
max_light = age * 3 

front_lights.start(max_light)
sleep(0.200)                                                    # dot
front_lights.stop()
sleep(0.200)                                                    # pause 

front_lights.start(max_light)
sleep(3 * 0.200)                                                # dash
front_lights.stop()
sleep(0.200)                                                    # pause 

front_lights.start(max_light)
sleep(0.200)                                                    # dot
front_lights.stop()
sleep(0.200)                                                    # pause   

GPIO.cleanup()

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

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