functions-and-modular-code

Unit 1: Functions and Modular Code

Deploy Jekyll with GitHub Pages dependencies preinstalled GitHub release MIT license

In our first unit we learn the basics of defining and calling functions, providing input parameters and return output values. And we define and describe the algorithms to solve our problems. Rearranging program code to become modular makes it easier to reuse code and reduce errors.

1 Welcome to Advanced Automation

1-1 Why Automation?

YouTube Video (1:52) - Although we hear about the negative sides of automation in today’s world, learning how to use automation ourselves is essential to seeing how it can be a force for good. In this first video of the automation course this year, I want to share some of the reasons why I am optimistic about what we are going to learn this year.

1-2 Building Automation

For this task, there are three tools you can explore how to build your own automated solutions to problems you face. You can choose any of them. Here are three videos describing how to build with each one:

Your task for the next class is to experiment with any of these tools to get a sense of how they work. Feel free to look for other tutorials out there to help you with any questions that might arise.

You must then build your own two automated tasks with any of the tools above. You should be prepared to explain the background context and the steps in the automation you build. Submit a single screenshot for each program in the assignment below.

1-3 Documenting and Decomposition

2 Introduction to Functions

2-1 Introduction to Functions

YouTube Explanation (6:08) - Last week we started looking at ways to break tasks down into individual steps. This video formalizes this using the programming concept of a function. You’ll learn some vocabulary of functions and ways to describe them using inputs, outputs, and how they relate to each other through algorithms.

2-2 Functions Case Study: Gmail Auto-reply

YouTube Video (10:43) - Using what I showed you in the last video, we take a look at code for my Gmail Auto-reply script and analyze functions for inputs, outputs, and algorithms. I show a few examples and leave the rest for you to do with your team. Along the way, we learn a bit about arrays, the logical OR operator, and some other elements of Javascript.

Template for Analysis - and assignment in Schoology

3 Shock Detector Case Study

This is microbit/shockdetector.js

3-1 Shock Detector Case Study

3-2 Accounts on Github and Replit

Accounts for Collaboration in Advanced Automation

4 Mastery Check - Sketch of Functions

4-1 Function Sketch Mastery Check

Following the style of what I did in the first video of breaking down the Shock Detector task, choose one of the problems mentioned in class and break it into a series of functions that each achieve a specific sub-task. For each function, identify the inputs and outputs to the extent that you can.

Template for students to copy and fill in ** Standard 3 formative

5 Make Code modular

5-1 Making Code Modular W3-1

In this skill-building activity, you will follow along with the video below to convert a single program into modular code organized into functions

This is microbit/modularCodeExampleStart.js

6 Module Maker - Creating modular code yourself!

6-1 Module maker - create code yourself ** standard 1 and 3 summative

Students create modular code and submit it. The code and description will be graded in the standards 1 and 3.

7 Drink Machine Part I

7-1 Drink Machine Project

Review of global and local variables in https://makecode.microbit.org/ Example code: https://makecode.microbit.org/_PMgfmrJg31tw

8 Drink Machine Part II

Reflect on the 3 stages when making a cup of coffee:

8-2 Drink Machine - Sharing Stage 1 W4-3 standard 4

Students submit the code that generates two of the drinks from the list as assigned from class.

8-3 Drink Machine Level Up videos

Now that you’ve played with Drink Machine and have done some things the long way, Mr. Weinberg is showing the better ways than the wait times and further details:

9 Drink Machine Testing Software

9-1 Drink Machine Testing Software

Copy the code from the following link into your program. It looks like this:

input.onButtonPressed(Button.A, function () {
    serial.writeLine("I start to make __specification-A__")
    // call your function here
})

input.onButtonPressed(Button.B, function () {
    serial.writeLine("I start to make __specification-B__")
})

// You can use the degree symbol ˚C in your specification
serial.writeLine("Press A for __specification-A__ and B for __specification-B__")

After pressing Button A and B it should generate the assigned drink. Assignments are done using the following programs:

For this project the code is project/drinkmachine.js