Make, Code, Have Fun

This site was created to collect all of our project done in our coding class.

Follow me on GitHub

Review

  • Technology
  • Core Programming Concept

IDE used: MakeCode

Technology

Using Microbit in our class has allowed us to get hands on experience on a lot of technology that enpowers of life daily. Physically interacting with them through coding and simple circuit helps us to get a sense of what they do and how they work.

lMicrobit feature

Technologies we interacted this semester include:

  • Sensors and electronics:
    • Light sensor
    • Temperature sensor
    • Accelerometer (for measuring motion and orientation)
    • DIY sensor (through electric current sensing)
    • GPIO (General purpose Input and Output)
      • Output music
      • Drive motors, etc
  • Data:
    • Collect
    • Display
    • Broadcast
  • Wired and Wireless Communication
    • UART (This is how your computer reads Microbit’s sensor)
    • Radio
    • Bluetooth
  • Message decoding and encoding (Morse code)

Microbit is capable of more, here are a few extra feature we haven’t tried.

  • Drive a motor
    • Driving RC car or boat
  • Control your phone via bluetooth
  • Connect to other electronics via serial bus and GPIO

Core Programming Skill

Here are a list of core programming concept that’s pretty common in most programming language, including Python, Java, Javascript, C, C++, etc.. Check how many of these you already know:

  • Cores
    • Variables
    • Conditionals
    • Loops
    • Functions
    • Lists, Maps, and other data structures
  • Advanced
    • Concurrent Programming
    • String Manipulation
    • Recursion
    • Object-Oriented Programming

Variables

my_variable = 5 # same as "set my_variable to 5" in block
your_variable = 6
my_variable = my_variable + 1  # same as "change my_variable by 1" in block
total = my_variable + your_variable # total = 12

Python does not require variable declaration, but many other language do. For example in Javascript:

var my_variable = 5;

Conditional

if (condition_A is True):
    print("Condition A is satisfied.")
    # Do task A
elif (condition_B is True):
    print("Condition B is satisfied.")
    # Do task B
else:
    print("None of the conditions are satisfied.")
    # Do task C
Block Flow chart
conditional block flow_chart

Loops

Compared to Scratch, we’ve encounter more flavors of loops

  • Forever loop, which runs forever until the Microbit powers down.
      while True:
          pass
          basic.pause(100)
          # This is equivalent to forever loop
    
  • Loop as long as condition is satisfied:
      while condition_A is True:
          # Do something as long as condition A is satisfied
    
  • Looping for finite number of times

      for i in range(10):
          pass
          # Do something for 10 times
          # Equivalent to repeat(10)
    
  • Loop through each element of an array

    • Loop by index (address):
        array_a = [1,3,5,1,3]
        for i in range(len(array_a)):
            # do something about the ith element of array_a
            # you can modify the content
      

      loop by address

    • Loop by content
        array_a = [1,3,5,1,3]
        for value in array_a:
            # use the content of the array
            # but you CANNOT modify it. 
      

      loop by content

Function

Function is used to define a specific task. Programmer use function everywhere. It help to break a large task into smaller sub-tasks, and write each tasks into a function. It helps to keep your mind clear, and your code clean.

def my_function(num: number, bool: bool, text: str):
    pass

function

List

List is the first data structure we encountered. It’s a multiple compartments storage of content with just one name.

list_a = [1,3,5,23]
list_b = ['a', 'b', 'c']

With data structure, it also comes with some standard ways of accessing content inside this storage. For example

# Access element by index
list_a[2] # this will give us 5
# Add more element at the end of the list
list_a.append(6) # list_a now becomes [1,3,5,23,6]
# Remove the first element from a list
list_a.shift()

We are not required to remember all of these method by heart. We can always search and read the documentation for the action we want to perform.

Event Handling

Today’s computer technology are much smarter and efficient. It no longer follow a strict sequence set by programmer to perform tasks. It has a mechanism to break a large tasks down to tiny tasks, and detect events between tasks, handle them on demand. This is the concurrent programming.

concurrent

We enable event handling by defining a call back function, and inserting sleep period in our main program which allows the processor to check on events.

# First we define the call back function
def on_button_pressed_a4():
    pass
# Then we hook the call back function to the event
input.on_button_pressed(Button.A, on_button_pressed_a4)
# Now, whenever Button.A is pressed, the callback function ```on_button_pressed_a4``` will be executed. 

callback

For the call back to work, we must have some sleep time in our main loop.

while True:
    pass
    basic.pause(100)
    # This is equivalent to forever loop

MakeCode gives us a block that does the Python code above: that’s the forever loop.

Text manipulation

Text manipulation is similar to list. We can actually treat a sentence as a list.

a=["I am going to school"]
a[0] # returns I
a[2] # returns a

Digging deeper into Python, text manipulation can gets more complicated though.

Object-Oriented Programming

This is probably the first time you hear these words, but you have used them in our project. When you call

music.play_melody("", 120)

You are executing the play_melody function belonging to object music. We will introduce OOP in pure Python class. But for now, if you see something.some_task(), you are already using object-oriented programming, except you are not the one who created these objects.

Summary

We can see, we have encountered quite a bit of core programming concept. Whichever language you will write your program in, these concepts pretty much all applies. Going forward, we need to concentrate on using these concepts to solve problem.

The art of programming, is not about writing code, but about solving problems.

  • Writing code is easy!
  • Defining and solving problem is hard!

Final Project

  • Goal 3: Health and well-being

    goal 3

    SDG 3 is a broad and ambitious Goal. It aims to achieve access to healthcare for everyone, everywhere. It aims to help people live more healthy lifestyles - for example eating more healthily and exercising regularly - and make the world we live in safer - for example by reducing air pollution and controlling disease outbreaks. It prioritizes both physical and mental health.

  • Goal 13: Climate Change

    goal 13

    Climate change includes both the global warming driven by human emissions of greenhouse gases, and the resulting shifts in weather patterns. Although the climate has changed at other times in the Earth’s history, this is the first time humans have caused it to change.

    Check out these google earth timelapse video

Define your problem

Now let’s discuss as a class, what problem we are facing for these two global goal, and what can we do about it.

  • Which global goal you chose, and why
  • Material:
  • Feature of the Product
  • Who does this design help?
  • Define your input, process, and output