Topic outline

  • Topic 1

    Introduction

    In the modern world of programming, large teams are assembled and a programming project is split into many teams, Think of a space launch. To be able to achieve this objective, a process called structured programming is used.

    Structured programming is a process where a program is broken up into its various parts, worked on independently, them combined into the fina lprogram.

    For students, this process helps them to learn how to think in a logical manner, which is important to solving problems in school and life.

    While sometimes difficult, it gives a sense of achievement when solved. This is called "hard fun".

    The Monty Python comedy team has had a profound impact on Western Culture. References to them can be found throughout computing. The Python language was actually named in honour of the boys.

    • Topic 2

      Every journey ...

      The first step is get your system up and running. 

      Follow the ink to the microbit.org quick start guide to make sure everything is running and you know how to upload code to the Micro:Bit.

      Use the microbit web site to guide you through the various functions of the microcontroller

      Full scale docs are here

      Microbit.org

      Microbit blockcode tutorials

      • Topic 3

        Before you start

        When you program a computer, there are three steps.

        • editing
        • interpreting
        • compiling

        editing

        you can edit code directly line by line into a command line in interpretive mode.

        or you can use an editor and save a series commands into a program as a text file.

        interpreter

        By saving it, it changes the text into an object file using an interpreter.

        linker

        a linker joins the object file to other files that are specific  the running of your microbit.

        micropi (mu)ieditor online

        • Topic 4

          Microprocessors

          A microprocessor is an electronic component that is used by a computer to turn things off and on. It is a central processing unit (CPU) on a single integrated circuit chip containing millions of very small components including transistors, resistors, and diodes that work together.

          Anything that has a red LED in it's circuitry or runs a clock like a microwave is controlled by microprocessors

          • Topic 5

            Sequential code

            A computer language is defined by there main constructs.

            • Sequence
            • Decision
            • Repetion
            Micro:Bit for Python starts here

            There is nothing to stop you from buying your own board and working at home or using school resources before, during and after school.

            Activity

            The countdown timer

            • Topic 6

              Data types : numbers, variables, strings

              A data type is a the way that Python stores data into memory.

              • Integers.
              • Floating-Point Numbers.
              • Complex Numbers.
              • Strings. Escape Sequences in Strings. Raw Strings. Triple-Quoted Strings.
              • Boolean Type, Boolean Context, and “Truthiness”
              • Built-In Functions. Math. Type Conversion. Iterables and Iterators. Composite Data TypeClasses, Attributes, and Inheritance. Input/Output. ..
              • Topic 7

                Sequence : manipulating images

                Syntax

                # Change the display using built-in image

                from microbit import *

                display.show(Image.HEART);

                Reading assignment

                Look through the following sites to give some ide of what you are doing. Code any of the examples you may like to try.

                Light it Up Tutorial

                Tutorial is here

                Hint

                See how this code will turn on different LEDs on the board. There are 25 LEDs and 25 digits. Can you work out which is which ?

                Code

                from microbit import *

                test = Image("05950:"
                "09590:"
                "00900:"
                "05950:"
                "59595")

                display.show(junk)

                Activity

                Use graph paper to plan your image and animation

                Use the graph paper to produce a graphical algorithm, them code from the planning. 

                Have at least three images in your animation

                from microbit import *

                Later on in your investigations, you will need to load code to run devices such as LCD screens, temperature sensors etc. These are downloaded from libraries and imported. * is a wildcard that downloads code such as how to send cosd to the microbit and back

                Challenges

                How do you

                • create a graphic 
                • clear a graphic
                • animate a graphic

                Exit ticket

                What result does the line

                test = Image("05950:"  

                produce in the microbit code?

                • Topic 8

                  The um editor

                   The micro:bit runs a special version of MicroPython (Mu). Mu was originally a contribution by the Python Software Foundation to this endeavour (along with the browser based editor on the project’s website).

                  code with Mu demo

                  code with mu editor

                  Mu has two modes. REPL interactive and flash code onto the chip. How the editor works

                  Activity using REPL

                  Load Mu. On the menu ribbon, select REPL. type each command into the edit window

                  >>>from microbit import *
                  >>>display.clear
                  >>>display.set_pixel(0,0,9)
                  >>>display.set_pixel(0,0,5)
                  >>>display.set_pixel(0,0,0)

                  You need to have the Mu editor running on your machine Detailed tutorial on the editor
                  • Topic 9

                    Variables, functions and forever loops

                    from microbit import *
                    from random import randint

                    display.clear

                    while True:
                       x = randint(0,4)
                       y = randint(0,4)
                       brightness = randint(0,1) * 9
                       display.set_pixel(x, y, brightness)
                       sleep (50)

                    Hack this code for only one pixel at a time 
                    How do the pixels get turned off?
                    • Topic 11

                      Repetition

                      Event loops

                      i = 1
                      while i < 6:
                        print(i)
                        i += 1

                      Reading assignment

                      While loops

                      For loops

                      Boolean operators

                      There are three logical operators that are used to compare values. They evaluate expressions down to Boolean values, returning either True or False . These operators are and , or , and not 

                      More later

                       

                       

                      Activity

                      Code for an image to be displayed when button A is not pressed, but changes when button A is presses

                      Materials

                      • Microbit
                      • cable
                      • crocodile leads
                      • piezo buzzer
                      • Topic 12

                        Decision : if ... elif ... else

                        Syntax

                        When code executes, it sometimes comes to a decision and needs to decide which path to take. Some languages call this branching, some call it forks

                        a = 200
                        b = 33
                        if b > a:
                          print("b is greater than a")
                        elif a == b:
                          print("a and b are equal")
                        else:
                          print("a is greater than b")

                        Reading Assignment

                        if ... then ... else in block code

                        use block code as an algorithm then code into python

                        if ... elif ... else

                        in python

                        Challenges

                        if .. ifel ... else is one of the fundamental control structures of any programming languages.

                        Use it to

                        change the image on your microbit using the either button

                         

                        Exit ticket

                        Write up the challenge in Google docs

                        Code it up in blockcode

                        Capture the code (algorithm)  in graphic package

                        Save into Google classroom

                        • Topic 13

                          Functions

                          A function is a mini program that can take in one or more values and return one result.

                          tell_the_time():

                            time.localtime([secs])

                          you can call for the local time whenever you like

                          tll_the_time

                          The rules for function names are the same as for variable names: letters, numbers
                          and some punctuation marks are legal, but the first character can’t be a number. You can’t use a
                          keyword as the name of a function, and you should avoid having a variable and a function with the
                          same name.


                          The empty parentheses after the name indicate that this function doesn’t take any arguments.
                          The first line of the function definition is called the header; the rest is called the body.

                          The header has to end with a colon and the body has to be indented. By convention, the indentation is always four spaces (see Section 3.13).

                          The body can contain any number of statements.

                          def print_lyrics():
                            print "I'm a lumberjack, and I'm okay."
                            print "I sleep all night and I work all day."

                          def repeat_lyrics():
                            print_lyrics()
                            print_lyrics()


                          repeat_lyrics()

                           

                          • Topic 14

                            Pinouts

                            The naked microbit hs 3 gpio and a gnd. 

                            Translated; the board has 3 general purpose input/output pins easily accessed by alligator clips and one ground. 

                            A circuit needs be connected for these to work.

                            See the microbit home page for more details.

                            microbit pinouts

                            There are in fact over 20 pins on the edge of the microbit board and they can be accessed easily by and edge connector. 

                             

                            There are 25 strips/pins including 5 rings for using with 4mm banana plugs or crocodile clips. 3 of these rings are for general purpose input and output (GPIO) and are also capable of

                            • analog,
                            • PWM
                            • touch sensing,

                            and two are connected to the micro:bit power supply.

                            • Topic 16

                              Writing your own program

                              • Topic 17

                                Input using an edge connector

                                • Topic 18

                                  Parameter passing using boolean parameters

                                  /*

                                  Boolean variables only have two values, 1, 0. They are valuable for being able to define a sketch as either off or on.

                                  This can be used with digitalWrite to turn a motor off or on, or stop a sketch running.

                                  */

                                  void setup()
                                  { // put your setup code here, to run once:
                                  pinMode(13, OUTPUT); }

                                  void loop() {
                                  blinx(1, 0); // use of boolean parameters
                                  }

                                  void blinx(int x1, int x2) {
                                  digitalWrite(13, x1);
                                  delay(1000);
                                  digitalWrite(13, x2);
                                  delay(1000);
                                  }

                                  • Topic 19

                                    Modules and classes

                                    • Topic 20

                                      Using a servo

                                      This uses an edge connector

                                      Materials

                                      • Microbit
                                      • cable
                                      • male/female Dupont lears
                                      • servo motor

                                      * may need extra power for servo

                                      • Topic 21

                                        Using a loop to run Pulse Width Modulation

                                        // Dim an LED using a PWM pin

                                        int PWMpin = 10; // LED in series with 470 ohm resistor on pin 1

                                        void setup() { // no setup needed } 

                                        void loop() { 
                                        bright(); 
                                        dark(); 


                                        void bright() { 
                                        for (int i=0; i <= 255; i++){ 
                                        analogWrite(PWMpin, i); 
                                        delay(10); 



                                        void dark(){

                                        for (int i=255; i >= 0; i--){ analogWrite(PWMpin, i);
                                        delay(10); 

                                        }

                                        • Topic 22

                                          Using a boolean value in an if .. them construct to control a loop


                                          // Dim an LED using a PWM pin

                                          int PWMpin = 10; // LED in series with 470 ohm resistor on pin 1
                                          boolean sentinal = true;

                                          void setup() { // no setup needed
                                          }

                                          void loop() {
                                          while (sentinal == true){
                                          bright();
                                          dark();
                                          }
                                          }

                                          void bright() {
                                          for (int i=0; i <= 255; i++){
                                          analogWrite(PWMpin, i);
                                          delay(10);
                                          }
                                          }
                                          void dark(){

                                          for (int i=255; i >= 0; i--){
                                          analogWrite(PWMpin, i);
                                          delay(10);
                                          }
                                          }

                                          • Topic 23

                                            Variables

                                            The word "vary" means being able to change. Learning any new subject brings us to a new vocabulary we need be familiar with.

                                            In computing, a variable is letter or word that can be assigned a value that changes.

                                            Often it is assigned to x, which was the old Greek letter chi, meaning "to change".

                                            Here is our first lesson in logic. In Arduino (C++) what does this symbol mean "="? You might (incorrectly) say "equals."

                                            Then what does this statement, used all the time in counting, mean?

                                            count = count +1?

                                            What does this mean?

                                            if (x=1,x==10,x++)?

                                            The first staement shoud be read as x "becomes 1", because the computer is making a memory location available for x to store a the value, 1.

                                            The statement x==1 should be read "x is the same as 1". It is a Boolean operator that evaluates to true of false. Dont panic if if it sounds wierd, it was named after George Boole, the English mathematician who wrote "Alice in Wonderland", but that is a story for another time.

                                            • Topic 24

                                              Input using buttons

                                              from microbit import *
                                              
                                                sleep(10000)
                                                display.scroll(str(button_a.get_presses()))