NSWI170 Computer Systems

Lab plan and learning outcomes

There are six labs and the learning outcomes of each lab are required for the next.

Lab #1 (C/C++ introduction)

The first lab should make you acquainted with the syntax of C-language. Students will create a simple application that works with arrays and prints on a console.

The first unforgivable curse introduced: code decomposition

Conceptual knowledge
  • basic C/C++ syntax (statements, functions, expressions)
  • principle of statically typed languages (in contrast with dynamically typed Python)
  • local vs. global variables
  • arrays, their organization in memory, array-pointer relationship in C
  • string literals their relationship with C pointers
  • code division (headers/cpp files), how preprocessor include headers
Practical skills
  • writing simple apps (similar to ones from basic programming course) in C/C++
  • printing string literals to std. output
  • processing data in arrays
  • compiling and executing C/C++ apps
  • using functions to organize and deduplicate code

Lab #2 (Blinking LEDs)

First introduction to Arduino board (with Funshield). Students will create a simple animation that uses the four-LED column on the shield.

The second unforgivable curse introduced: using constants

Conceptual knowledge
  • how Arduino board works and how code is being uploaded
  • physical features of Arduino board and Funshield
  • Arduino programming interface (setup() and loop() functions)
  • reactive programming model (loop() should not block)
  • how to do timing (for an animation) with time measurement functions
Practical skills
  • writing Arduino apps in Arduino IDE, compiling them, uploading them to the device
  • using digital output pins
  • using internal timing functions
  • using constants (instead of literals) properly in the code

Lab #3 (Buttons)

Introduction of hardware inputs (buttons) to control the device. The first application is a simple counter incremented/decremented by buttons and visualized in binary using LEDs.

The third unforgivable curse introduced: don't repeat yourselves

Conceptual knowledge
  • drawbacks of physical hardware input (button oscillation) and how to solve them (button debouncing)
  • understanding logical bitwise operations in depth (and, or, shifts)
  • importantance of keeping the code DRY and how to achieve it
Practical skills
  • using modulo arithmetic
  • reading data from digital pins
  • using logical bitwise operations for masking (reading a particular bit from a word)
  • handling more complex timing (that includes state)
  • techniques for reducing code redundancy (with functions, loops, and arrays)

Lab #4 (Segment display)

The counter application will be modified to use a 7-segment LED display, so the value is easily readable by humans. The display uses matrix control, so we will use it to display one digit at a time for now.

The fourth unforgivable curse introduced: inappropriate usage of global variables

Conceptual knowledge
  • fundamentals of shift registers
  • the principle of display matrix control
  • why is it best to avoid utilization of global variables
  • where are global variables necessary (in Arduino code)
Practical skills
  • writing data to a shift register, using output latches
  • encoding digits for the 7-seg. display
  • passing arguments to functions by reference
  • using structures/classes (wrapping variables into higher logical constructs)

Lab #5 (Stopwatch)

Students will use time multiplexing to create an illusion that different display positions show different digits. Furthermore, the logic of the application will be changed from a counter to a simple stopwatch.

The fifth unforgivable curse introduced: encapsulation and interfaces

Conceptual knowledge
  • concept of time multiplexing (for illuding human eyes)
  • time measurement and possible pitfalls
  • idea of code encapsulation and basic means how to achieve it
Practical skills
  • implementing precise timing (for stopwatch)
  • implementing state-dependent behavior for the buttons
  • separating the code into logical blocks (e.g., by classes), like input handling, display control, or stopwatch logic
  • designing appropriate interface between the blocks
  • handling independent tasks (time measurement, display refreshing, and input processing) in the main loop together

Lab #6 (Running message)

The last lab session is about practicing C-strings using the segment display to visualize a running text message. The messages are set from the host PC via a USB serial link.

The lab tests are explained and a sample test assignment is introduced.

Conceptual knowledge
  • communication with Arduino over serial link
  • using a 3rd party code, programming against the interface
  • how arrays, strings (zero ended), and raw pointers work in C
  • relation between references and pointers
  • pitfalls of C pointers (accessing invalid addresses)
  • meaning of nullptr
  • static allocation of string buffers and the danger it poses
Practical skills
  • using C strings and iterating over them with pointers
  • displaying a 4-letter substring on the display
  • handling corner cases of string processing and string scrolling (leading spaces, too short and empty strings)
  • receiving data from serial link
  • proper usage of const with pointers