NSWI170 Computer Systems
4th practicals
Agenda
- Arduino buttons review
- Introduction to C++ classes and structs
- Example classes and how to use them
- Working with display
- Code quality: Inappropriate usage of global variables
- New assignment: Arduino 7-seg display
Do not forget...
- You MUST have 100% in ReCodEx by the end of the next Tuesday after the assignment is announced.
- You MUST decompose your code.
- You MUST use constants and derive all derivable values from them.
- You MUST not repeat your code.
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