NSWI170 Computer Systems

4th practicals

Agenda

  1. Arduino buttons review
  2. Introduction to C++ classes and structs
  3. Example classes and how to use them
  4. Working with display
  5. Code quality: Inappropriate usage of global variables
  6. New assignment: Arduino 7-seg display

Do not forget...

constexpr int modulo = 1 << ledsCount;

ReCodEx limitations

Classes

class Button {
private:
  int pin;

public: 
  // Constructor
  Button(int _pin) {
    pin = _pin;
  }
  
  bool isDown() {
  	return !digitalRead(pin);
  }
};

// Create the instance with name "button" and call the constructor
Button button(button1_pin);

// Use it
if (button.isDown()) {

}

Restrict use of global variables

displayNumber();
displayNumber(counter);

Assignment 4

How much would you need to change your code?

  • The counter still exists, but the range is different.
    change in range
  • There is a third button that controls another variable.
    create, register, implement handling
  • Instead of using LEDs, use 8 segment display.
    replace one function with another

NSWI170 - 4th practicals

By Štěpán Stenchlák

NSWI170 - 4th practicals

  • 165