© 2018 SAM Labs Binary Patterns
Mini-lesson
Using the website
https://www.w3schools.com/
colors/colors_picker.asp can
you find the color that this
hex code generates?
Let’s Discuss
1. What color is #ff0000?
A. Green
B. Blue
C. Red
2. In your workbook or with a partner, record, discuss, or share why hex was created.
Step 1.
Drag on a Program Start block from the ‘General’ tab.
Step 2.
Create a Variable called ‘userinput’.
Step 3.
Check the variable is created in the ‘Variable’ tab.
Worked Example
Step 4.
Drag on from within the ‘Variable’ tab a ‘set variable to’ block
Step 5.
Drag on from the ‘General’ tab the block starting with the wording ‘prompt’
Step 6.
In the light blue block, set the question to ‘What is your name?’.
Worked Example
Step 7. From the ‘General’ tab, drag on a Print block. Connect under the ‘userinput’ block within the Program Start block.
Step 8.
From the ‘Variable’ tab, select the ‘userinput’ block. Replace the light blue text block with it.
Step 9.
Test your system by pressing ‘RUN’.
Worked Example
Challenge 1
Step 1.
● Remove the ‘Print’ block. ● Edit the text to ‘What is the hex code?’
Step 2.
Remove the block from the ‘Program start’ block.
Step 3.
From the Loop tab, drag on a ‘Repeat forever’ block and connect to ‘Program start’ block.
Challenge 1
Step 4.
Connect the ‘set user input’ block to the ‘Repeat forever’ block.
Step 5.
Turn on and ‘Connect’ the RGB LED by clicking ‘Add device’ and select the RGB LED block. Press and hold the power button on the block and select ‘connect’ and ‘PAIR’ on the Devices section of SAM Blockly.
Step 6.
From the RGB Light actions tab, drag on a ‘set RGB Light LED to’ block and connect the ‘set userinput’ block.
Challenge 1
Step 7.
From the Variable tab, drag and replace the color red with the ‘userinput’ variable.
Step 8.
Test your system and add the hex code #ff0000.
Checks for Understanding
1. How many variables are there within the system?
A. 1
B. 2
C. 3
2. What is the definition of a variable?
A. A fixed value
B. A value that can be changed
C. A value range
Challenge 1 - Debug it!
Step 1.
From within the ‘General’ tab, drag on a ‘Wait 2 seconds’ block. Connect under the ‘set RGB Light’ block.
Step 2.
From the RGB Light Actions tab, drag on a ‘Turn RGB Light LED off’ block. Connect it underneath the ‘Wait 2 seconds’ block.
Challenge 2
Step 1.
Use the test table in your student workbook to efficiently test your program.
Step 2.
Complete the first test ‘remove the hash tag’.
Step 3.
Complete the second test a hex code larger than the range ‘GGHHGG’.
Challenge 2
Step 4.
Complete the test table on the next pagefor the color codes and compare your results to website color picker.
Step 5.
Add new Hex codes to the test table and test them.
Challenge 2Complete the test table for the color codes and compare your results to website color picker.
Add new Hex codes to the test table and test them.
Hex Code Expected outcome Actual outcome
#ff0000
#GGHHGG
#00ff00
#0000ff
#ffff00
#ffc0cb
#800080
#00ccff
Checks for Understanding
1. What is the purpose of the ‘Repeat Forever’ block?
A. To repeat the actions once
B. To repeat the actions for a set number of times
C. To continuously repeat the actions
2. What is a loop?
A. Sequence of instructions
B. Sequence of instructions repeated until a certain
condition is reached
C. Set of step by step instructions