Go to the latest lesson. See all classes.

Classroom and Self-Directed Learning Resources

First Day, 2024-03-12

Welcome to Computer Science

Join Your Class in Google Classroom

Computing in the News

Women in computing

MakeCode for micro:bit

Self-Directed Learning


micro:bit game

micro:bit game

Self-Directed Learning


Computing in the News: Grace Hopper


  • When did she live?
  • Where did she get her math and physics degrees?
  • Where did the term “debugging” come from?
  • What programming language did she help develop?
  • What computers did she work on at Harvard?
  • What did she say is her greatest accomplishment?

Programming the micro:bit in Python

micro:bit Python editor

Explore examples in the Ideas tab.

Self-Directed Learning


Programming the micro:bit in Python

micro:bit Python editor

Tilting Dot Program

from microbit import *

x = 2
y = 2

while True:
    ax = accelerometer.get_x()
    if ax > 200 and x < 4:
        x += 1
    if ax < -200 and x > 0:
        x -= 1

    ay = accelerometer.get_y()
    if ay > 200 and y < 4:
        y += 1
    if ay < -200 and y > 0:
        y -= 1

    display.set_pixel(x, y, 9)


Explanation of the Code

(from Google Gemini Advanced)

Setting Up

  • from microbit import * This line tells the computer to use a module called “microbit” to control the micro:bit.

Our Characters

  • x = 2
  • y = 2 Just like in a story, we have characters x and y. They keep track of where something is shown on the screen, like where a game character might start.

The Main Loop (Happens Repeatedly)

  • while True: This line says, “Keep doing the things inside this block of code over and over again!”

Sensing Movement

  • ax = accelerometer.get_x()
  • ay = accelerometer.get_y() The micro:bit has a special sensor to detect how it’s tilted. These lines find out how much it’s tilted sideways (ax) and up-and-down (ay).

Moving Right

  • if ax > 200 and x < 4: If… the micro:bit is tilted a lot to the right (more than a number 200) and our character x isn’t all the way to the right edge (less than a number 4), then…
    • x += 1 This line moves our character x one step to the right.

Moving Left, Up, and Down (Similar to Moving Right)

These parts of the code work similarly to how we checked for moving right.

Drawing and Clearing

  • display.clear() This line erases anything that was previously shown on the micro:bit’s tiny screen.
  • display.set_pixel(x, y, 9) This line draws a bright dot (because 9 means bright) on the screen.

Short Pause

  • sleep(250) This line tells the computer to wait.


Computing in the News

U.S. hits Apple with landmark antitrust suit, accusing tech giant of stifling competition

Tinkercad Circuits


Computing in the News

Google to destroy billions of data records to settle “incognito” lawsuit

Tinkercad Circuits

Self-Directed Learning