More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

My Timetable in HTML / CSS

my-timetable

Learning Objectives


In this challenge we are learning how to draw and format a table on a web page using a range of HTML tags and CSS properties.

HTML Tables


First you may want to read a bit more about how HTML tables are built using the <TABLE>, <THEAD>, <TBODY>, <TR>, <TH> and <TD> HTML tags.

CSS Code


Remember the key syntax for CSS is as follows:
css-syntax

In this challenge we will use various CSS properties such as:

  • font-family:
  • font-size:
  • color:
  • font-weight:
  • font-style:
  • text-align:
  • padding:
  • background-color:
  • etc.

You can learn more about all these CSS properties on w3schools.com.

We will also use different types of selectors such as:

  • TAG
  • .class
  • #id
  • element child-element
  • element child-element:first-child

You can learn more about CSS selectors on w3schools.com.

My Timetable


We have created a timetable for you.

Task 1: By changing the HTML code, you can now change the content of this timetable: you can add your own lessons to reproduce your own timetable. You may want to change the structure of the day (e.g. Does your school day consist of 5 lessons?) by adding or deleting rows to this timetable.

Task 2: By changing the CSS code, you can now change the look & feel of your timetable. Change the colour scheme, the choice of fonts, the spacing (padding / margin) between table cells, etc.

See the Pen My Timetable by 101 Computing (@101Computing) on CodePen.


Press the “Edit on CodePen” button at the top of this codepen to open in full screen mode

Tagged with:

Minesweeper in Javascript

minesweeperIn this blog post we will work on the classic game of Minesweeper. Minesweeper is a single-player puzzle video game. The objective of the game is to clear a rectangular board containing hidden “mines” or bombs without detonating any of them, with help from clues about the number of neighbouring mines in each field. The game originates from the 1960s, and has been written for many computing platforms in use today.

We have created a fully working version of the game using HTML, CSS and JavaScript. Your task will be to reverse-engineer the code to be able to improve this game further.

Full Code

See the Pen Minesweeper by 101 Computing (@101Computing) on CodePen.

Your Challenge


Improve this code further to:

  • Calculate and display a score in real time (number of cells that have been visited).
  • Allow the user to add a cross to a cell (by right clicking?) to indicate the position of a mine.
  • Allow the user to choose a difficulty level or change some settings (e.g. Number of mines, size of the grid).
  • Add a timer to the game.

Fetching Data using a Multiplexer

In our previous blog posts we have looked at a few logic gates circuits used inside a CPU to perform binary additions (Half adders and full adders) and to retain a bit of information using a D-Type flip-flop circuit (Data Cell).

By studying assembly language (using the LMC simulator) we have aslo investigated how the CPU uses the FDE cycle to fetch an instruction, decode it and execute it.

The purpose of this blog post is to investigate how the CPU can fetch data (data or instructions) from memory as this is an essential part of the FDE cycle.

Multiplexer?


A multiplexer is a logic gates circuit used to fetch a bit of data from memory at a given memory address. A processor has several multiplexers (MUX) controlling the data and address buses. Multiplexers are switches allowing the processor to select data from multiple data sources. To select which data source should be used a multiplexer has one or more control lines (a.ka. Selectors). The output of a multiplexer is the selected data.

Let’s investiagte a basic multiplexer used to select data from two data cells. With only two data cells (A and B) you only need 1 bit to code their address:

  • Address 0 = Input A
  • Address 1 = Input B
Multiplexer - 2 Inputs

Multiplexer – 2 Inputs

The Truth Table of this 2-input Multiplexer is:

Multiplexer 2 Inputs - Truth Table

Multiplexer 2 Inputs – Truth Table

By combining two of these multiplexers together we can select between 4 inputs, A, B, C and D.

Multiplexer - 4 Inputs

Multiplexer – 4 Inputs

In this multiplexer we have two selectors: S1, S2 to get the following outputs from the 4 memory addresses: 00,10,01 and 11:

Multiplexer 4 Inputs - Truth Table

Multiplexer 4 Inputs – Truth Table

This is how our 4-input multiplexer behaves:

Multiplexer 4 Inputs

Multiplexer 4 Inputs

By combining more of these multiplexers together we can fetch data from 4-bit memory locations or 8-bit memory locations and so on.

Note that:

  • With 1 multiplexer (2 inputs, 1 selector) we can fetch data from 2 memory locations.
  • With 2 multiplexers (4 inputs, 2 selectors) we can fetch data from 4 memory locations.
  • With 3 multiplexers (8 inputs, 3 selectors) we can fetch data from 8 memory locations.
  • With 4 multiplexers (16 inputs, 4 selectors) we can fetch data from 16 memory locations.
  • With N multiplexers (2N inputs, N selectors) we can fetch data from 2N memory locations.

From bits to Bytes


Previously, (see blog post) we have seen that a data cell consists of a D-Type flip-flop logic gates circuit and holds one bit of data.

In the CPU, registers, Level 1 cache and in he RAM, memory units use such data cells.
By lining up 8 data cells in parallel, we can then store 1 Byte (8-bits) of data.

To retrieve the content of an 8-bit memory unit, we can connect 8 multiplexers in parallel.

Address Bus & Data Bus


The “wires” between the multiplexers and the data cells are called buses. In an 8-bit processor each bus consists of 8 wires in parallel.

The buses that connect the inputs (e.g. A,B,C,D in the diagram above) are called data buses as they carry the actual data to be fetched.

The buses that connect the selectors (e.g. S1 and S2) are called address buses as they carry the address of where the data is to be fetched from. The more wires in the address bus, the more memory locations can be reached (2N), so:

  • For an address bus of 8 wires you can reach 256 memory locations,
  • with 16 wires (2-Byte addresses) you can reach over 64,000 memory locations,
  • with 32 wires (4-Byte addresses) you can reach over 4,000,000,000 memory locations. (e.g. 4GB RAM)

electronic-circuit

Data or Instructions?


Through the FDE cycle, the CPU has to fetch instructions (lines of machine code to execute) as well as data (e.g. oerands). In a Von Neumann processor architecture, both instructions and data are stored in the same locations using the same format. The same multiplexers can hence be used to fetch either data or instructions.

Tagged with: ,

Happy New Year Animation

happy-new-year-textIn this challenge we will use Python code to create a text-based (ASCII) animation to be used as a final countdown before the new year!

Our countdown timer will be based on a for loop to count down from 5 to 0. It will also make use of the sleep() function from the time library to allow 1 second between each iteration of the for loop.

Check our two animations below:

5-4-3-2-1 Hapy New Year! - Version 1.0Version 2.0

Version 1.0



Version 2.0


This animation makes use of 10 procedures called one(), two(), three(),…, up to ten() to improve the output of our countdown timer. These procedures are all stored in a module called myNumbers.


More Text-Based Animations


Visit this blog post to find the code for more text-based animations and start creating your own animations.

Tagged with: ,

Little Man Computer – Max Function

LMC-MaxIn this challenge we will create a computer program using LMC (Little Man Computer) that takes two inputs and outputs the larger (max) of the two inputs.

By completing this challenge we will investigate the use of the branching instructions BRP and BRA to create an IF THEN ELSE selection.

Flowchart


We have produced the flowchart of our max algorithm using LMC instructions:
LMC_Flowchart_Max

LMC Simulators


You can now type and test this code using one of the following online LMC Simulators:

LMC Instruction Set


Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.

Mnemonic Name Description Op Code
INP INPUT Retrieve user input and stores it in the accumulator. 901
OUT OUTPUT Output the value stored in the accumulator. 902
LDA LOAD Load the Accumulator with the contents of the memory address given. 5xx
STA STORE Store the value in the Accumulator in the memory address given. 3xx
ADD ADD Add the contents of the memory address to the Accumulator 1xx
SUB SUBTRACT Subtract the contents of the memory address from the Accumulator 2xx
BRP BRANCH IF POSITIVE Branch/Jump to the address given if the Accumulator is zero or positive. 8xx
BRZ BRANCH IF ZERO Branch/Jump to the address given if the Accumulator is zero. 7xx
BRA BRANCH ALWAYS Branch/Jump to the address given. 6xx
HLT HALT Stop the code 000
DAT DATA LOCATION Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.
Tagged with: ,

Little Man Computer: Countdown Timer

countdown_animatedIn this challenge we will create a computer program using LMC (Little Man Computer) that takes a number as an input (e.g. 5) and outputs a countdown from this value. (e.g: 5.4.3.2.1.0).

By completing this challenge we will investigate the use of the branching instruction BRP to create a looping effect.

Flowchart


We have produced the flowchart of our countdown timer using LMC instructions:
LMC-Flowchart-Countdown

LMC Simulators


You can now type and test this code using one of the following online LMC Simulators:

LMC Instruction Set


Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.

Mnemonic Name Description Op Code
INP INPUT Retrieve user input and stores it in the accumulator. 901
OUT OUTPUT Output the value stored in the accumulator. 902
LDA LOAD Load the Accumulator with the contents of the memory address given. 5xx
STA STORE Store the value in the Accumulator in the memory address given. 3xx
ADD ADD Add the contents of the memory address to the Accumulator 1xx
SUB SUBTRACT Subtract the contents of the memory address from the Accumulator 2xx
BRP BRANCH IF POSITIVE Branch/Jump to the address given if the Accumulator is zero or positive. 8xx
BRZ BRANCH IF ZERO Branch/Jump to the address given if the Accumulator is zero. 7xx
BRA BRANCH ALWAYS Branch/Jump to the address given. 6xx
HLT HALT Stop the code 000
DAT DATA LOCATION Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.
Tagged with: ,

Little Man Computer: Mini Challenges

By completing this set of 12 mini challenges you will write programs using Little Man Computer using all the instructions of the LMC instruction set (See below). You will start with basic Input / Process / Output challenges based on sequencing. You will then investigate branching instructions (BRP, BRZ, BRA) to write programs using selection (a.k.a. branching) and iteration (a.k.a. loops).

LMC Simulators

LMC Instruction Set


Note that in the following table “xx” refers to a memory address (aka mailbox) in the RAM. The online LMC simulator has 100 different mailboxes in the RAM ranging from 00 to 99.

Mnemonic Name Description Op Code
INP INPUT Retrieve user input and stores it in the accumulator. 901
OUT OUTPUT Output the value stored in the accumulator. 902
LDA LOAD Load the Accumulator with the contents of the memory address given. 5xx
STA STORE Store the value in the Accumulator in the memory address given. 3xx
ADD ADD Add the contents of the memory address to the Accumulator 1xx
SUB SUBTRACT Subtract the contents of the memory address from the Accumulator 2xx
BRP BRANCH IF POSITIVE Branch/Jump to the address given if the Accumulator is zero or positive. 8xx
BRZ BRANCH IF ZERO Branch/Jump to the address given if the Accumulator is zero. 7xx
BRA BRANCH ALWAYS Branch/Jump to the address given. 6xx
HLT HALT Stop the code 000
DAT DATA LOCATION Used to associate a label to a free memory address. An optional value can also be used to be stored at the memory address.

Mini Challenges


LMC-Challenge-1

LMC-Challenge-2

LMC-Challenge-3

LMC-Challenge-4

LMC-Challenge-5

LMC-Challenge-6

LMC-Challenge-7

LMC-Challenge-8

LMC-Challenge-9

LMC-Challenge-10

LMC-Challenge-11

LMC-Challenge-12

Tagged with: ,

BCD to 7-Segment Display

7-segment-display

What is BCD code?


In computing and electronic systems, binary-coded decimal (BCD) is used to encode decimal numbers (base-10 numbers) in a binary form where each decimal digit is represented by a nibble (4 bits).

For instance decimal number 5 is represented as 0101 in BCD as 5 = 4 + 1

8 4 2 1
0 1 0 1

The 10 digits in BCD:

Decimal Digit BCD Nibble
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Numbers larger than 9, having two or more digits in the decimal system, are expressed one digit at a time using on nibble per digit. For example, the decimal number 365 is encoded as:

0011 0110 0101

7-Segment Display


A lot of electronic devices use 7-segment displays (Watch, alarm clock, calculator etc.).
Typically 7-segment displays consist of seven individual coloured LED’s (called the segments). Each segment can be turned on or off to create a unique pattern/combination. Each segment is identified using a letter between A to G as follows:

7-segment-display-connections

The 10 descimal digits can be displayed on a seven-segment display as follows:

BCD to 7-Segment Display: Truth Tables & Karnaugh Maps


We will use four inputs A,B,C and D to represent the four BCD digits as ABCD (A is the most significant digit, D is the least significant digit). When creating an electronic circuit we could use 4 switches to represent these 4 inputs.

We will need 7 outputs one for each segment. So let’s investigate each segment one at a time.

Segment ABCDEFG
Segment A should be on for the following values:

tmp-0BCD: 0000 tmp-0BCD: 0010 tmp-0BCD: 0011 tmp-0BCD: 0101
tmp-0BCD: 0110 tmp-0BCD: 0111 tmp-0BCD: 1000 tmp-0BCD: 1001

Segment A should be off for the following values:

tmp-0BCD: 0001 tmp-0BCD: 0100

Segment A should also be off for the following BCD values which are not used to represent decimal digits values from 0 to 9:

  • 1010
  • 1011
  • 1100
  • 1101
  • 1110
  • 1111

Note that these values could be used to represent hexadecimal values A to F (10 to 15). Here we will not display anything instead.

Hence the Truth Table for Segment A is as follows:

Inputs Output
A B C D Segment A
0 0 0 0 1
0 0 0 1 0
0 0 1 0 1
0 0 1 1 1
0 1 0 0 0
0 1 0 1 1
0 1 1 0 1
0 1 1 1 1
1 0 0 0 1
1 0 0 1 1
1 0 1 0 0
1 0 1 1 0
1 1 0 0 0
1 1 0 1 0
1 1 1 0 0
1 1 1 1 0

This Truth table can be represented using a Karnaugh Map:

Karnaugh Map for Segment A

Karnaugh Map for Segment A

Follow the same process to define the Truth Table and Karnaugh Map of the B segment:

Follow the same process to define the Truth Table and Karnaugh Map of the C segment:

Follow the same process to define the Truth Table and Karnaugh Map of the D segment:

Follow the same process to define the Truth Table and Karnaugh Map of the E segment:

Follow the same process to define the Truth Table and Karnaugh Map of the F segment:

Follow the same process to define the Truth Table and Karnaugh Map of the G segment:

BCD to 7-Segment Display: Boolean Expressions


The Karnaugh maps will help us define the Boolean Expressions associated with each of the 7 segments.

Segment ABCDEFG
Karnaugh Map:
Karnaugh Map - Segment A

Karnaugh Map – Segment A

Boolean Expression:
Booelan Expression for Segment A

Boolean Expression for Segment A

Use the Karnaugh Map for the B segment to define the Boolean Expression of the B segment.
Use the Karnaugh Map for the C segment to define the Boolean Expression of the C segment.
Use the Karnaugh Map for the D segment to define the Boolean Expression of the D segment.
Use the Karnaugh Map for the E segment to define the Boolean Expression of the E segment.
Use the Karnaugh Map for the F segment to define the Boolean Expression of the F segment.
Use the Karnaugh Map for the G segment to define the Boolean Expression of the G segment.

BCD to 7-Segment Display: Logic Gates Diagrams


We can now convert each Boolean expression into a Logic Gates circuit to link our 4 inputs (switches) to our 7-segment display using a range of logic gates.
Segment ABCDEFG
Boolean Expression:
Booelan Expression for Segment A

Booelan Expression for Segment A

Logic Gates Diagram:
Segment A - Logic Gates Diagram

Segment A – Logic Gates Diagram

Use the Boolean Expression of the B segment to draw the logic gates diagram required to control the LED of the B segment.
Use the Boolean Expression of the C segment to draw the logic gates diagram required to control the LED of the C segment.
Use the Boolean Expression of the D segment to draw the logic gates diagram required to control the LED of the D segment.
Use the Boolean Expression of the E segment to draw the logic gates diagram required to control the LED of the E segment.
Use the Boolean Expression of the F segment to draw the logic gates diagram required to control the LED of the F segment.
Use the Boolean Expression of the G segment to draw the logic gates diagram required to control the LED of the G segment.

Testing


You can now recreate your logic gates circuit using logic.ly to test if it behaves as expected for all 16 BCD entries.
e.g. For Segment A:
Logic Gates Circuit for Segment A

Logic Gates Circuit for Segment A

BCD to 7-Segment Display Integrated Circuit


integrated-circuitAll these 7 logic gates diagrams can all be integrated into one single integrated circuit: The CD74HCT4511E is a CMOS logic high-speed BCD to 7-segment Latch/Decoder/Driver with four inputs and is used to use these 4 inputs (BCD nibble) to control the display of a 7-segment display.

Hex/BCD to 7-Segment Display Integrated Circuit


A very similar approach can be used to display hexadecimal digits as these are also based on a nibble per digit.

The extra values that we discarded previously (BCD: 1010, 1011, 1100, 1101, 1110, 1111) can be used to represent the extra 6 digits available in hexadecimal:

BBC micro:bit Counter using a 7-Segment Display

7-segment-displayThe aim of this challenge is to create a countdown timer, controlled by a BBC micro:bit that will display the numbers on a screen using a 7-segment display. A lot of electronic devices use this approach to display numbers on a LED or LCD screen. (Watch, alarm clock, calculator etc.)

Typically 7-segment displays consist of seven individual coloured LED’s (called the segments). Each segment can be turned on or off to create a unique pattern/combination. Each segment is identified using a letter between A to G as follows:

7segments

The following truth table shows which segments need to be on to display the digits from 0 to 9:

Digit A B C D E F G
tmp-0 1 1 1 1 1 1 0
tmp-1 0 1 1 0 0 0 0
tmp-2 1 1 0 1 1 0 1
tmp-3 1 1 1 1 0 0 1
tmp-4 0 1 1 0 0 1 1
tmp-5 1 0 1 1 0 1 1
tmp-6 1 0 1 1 1 1 1
tmp-7 1 1 1 0 0 0 0
tmp-8 1 1 1 1 1 1 1
tmp-9 1 1 1 1 0 1 1

Step 1: The electronic circuit


7-segment-display-connectionsTo complete this challenge you will need:

  • 1 breadboard
  • 8 resistors of 220Ω each
  • 1 7-segment display (common anode)
  • 1 BBC micro:bit
  • 1 micro:bit edge connector
  • 20 wires

Here is the circuit that you will need to re-create:
micro-bit-7-segment

Step 2: Python Code

To program your BBC micro:bit you will use the Python editor and copy and paste the following code:

#micro-bit Counter using a 7-Segment Display - www.101computing.net
from microbit import *

pins = [pin0, pin1, pin2, pin8, pin12, pin13, pin14, pin15]
digits = ["11111100","01100000","11011010","11110010","01100110",
          "10110110","10111110","11100000","11111110","11110110"]

while True:
    for i in range(0,10):
        bits=digits[i]
        for j in range(0,8):
            pins[j].write_digital(int(bits[j]))
        display.scroll(str(i))
        sleep(1000)

Your 7-segment display should display all the digits, counting up from 0 to 9.

Your Challenge


countdown_animatedUpdate the code to:

  • Create a count down timer, going from 9 to 0.
  • Allow the user to pause and restart the countdown timer using the A and B buttons of the micro:bit.
Tagged with:

Logic Gates Tester Kit

3rd Generation computers used integrated circuits.

3rd Generation computers used integrated circuits.

The purpose of this challenge is to create an electronic circuit used to test and identify logic gates integrated circuits.

Logic gates are built as integrated circuits (also referred to as chips, or microchips). An integrated circuit is a set of electronic circuits on one small flat piece (or “chip”) of semiconductor material, normally silicon. The integration of large numbers of tiny transistors into a small chip results in circuits that are smaller, cheaper, and faster than those constructed of discrete electronic components.

Each circuit has a code printed on them which is used to identify the circuit. (e.g. See List of 7400 series integrated circuits on https://en.wikipedia.org/wiki/List_of_7400_series_integrated_circuits)

Each circuit is different and you need to know how the circuit is wired internally to use it in your own circuits (to indentify the purpose of each pin). See image below as an example of integrated circuit 7408 which consists of four AND gates.

Integrated Circuit 7408: Quad 2-input AND gate

Integrated Circuit 7408: Quad 2-input AND gate

Your Challenge


For this challenge, we will assume that you have some integrated circuits (ICs) but do not know which logic gates they consist of. Instead of looking up for their code on the Internet, you will create an electronic circuit and use this circuit to test how your IC behaves. Your circuit will have:

  • Two inputs: the yellow and a blue button on the diagram below.
  • One output: the green LED on the diagram below.

logic-gate-tester

By using the buttons and writing down the outputs, you will be able to draw the truth table of this logic gate and hence identify which logic gate is used in this IC.

Input A Input B Output
0 0
0 1
1 0
1 1

Check this blog post to investigate the truth tables for some of the key logic gates.

Logic Gates circuits available on: kitronik.co.uk.