NSWI170 Computer Systems
Arduino
The first order of business is to get your own Arduino within the first two weeks! You can either buy it or borrow it from the library at Mala Strana (only there!). If you are going to the library for the first time it might be a good idea to register first to speed up the process. There is an online registration form you may use.
The Arduino you borrowed is equipped with a FunShield which provides a decent user interface (buttons, LEDs, and 7seg display). To use it, you will require a Funshield.zip library. It needs to be installed once (which we will do step by step in the labs) into Arduino IDE, then you can use it as a C++ header.
ReCodEx submissions
Your solutions should be submitted to ReCodEx for validation and archiving. Please, always submit only the solution.ino
file unless specified otherwise. The teachers will use ReCodEx to give you feedback via code reviews.
ReCodEx uses a Moccarduino emulator to test your solution. It emulates the Arduino API on a functional level and provides helpers to write testing scenarios that use the FunShiled. There are certain limitations and differences from the actual Arduino hardware, please read the associated README. Furthermore:
- ReCodEx validation is much more strict, especially considering the timing measurements. Be precise in your timings since very small differences cannot be spotted by the naked eye when debugging on the real hardware, but ReCodEx will reveal them.
- ReCodEx output tries to be user-friendly, but sometimes it might get confusing. If you double-check the assignment specification and your code and you assume it is working correctly on the real hardware, contact your teacher to help you solve the issue. Lab teachers have access to testing scenarios and additional tools so they can give you more hints.
- Stick to the official Arduino API (documented functions). Using some more elaborate techniques or hacks (e.g., writing directly to registers) will not work in the emulator. This also implies you cannot use advanced features like timers or interrupts.
- Some things are explicitly prohibited (the emulator supports them, but you are not allowed to use them in your assignments). Most notably, you must not block the execution of
loop()
. For the same reason,delay()
and similar functions from the API are disabled.
Focus also on the quality of your code and check out the coding guidelines.
Header file funshield.h
Defines important constants that you will require when working with FunShield. Do not submit this file in ReCodEx (it is automatically included).
#ifndef FUNSHIELD_CONSTANTS_H__
#define FUNSHIELD_CONSTANTS_H__
// convenience constants for switching on/off
constexpr int ON = LOW;
constexpr int OFF = HIGH;
// 7-segs
constexpr int latch_pin = 4;
constexpr int clock_pin = 7;
constexpr int data_pin = 8;
// buzzer
constexpr int beep_pin = 3;
// LEDs
constexpr int led1_pin = 13;
constexpr int led2_pin = 12;
constexpr int led3_pin = 11;
constexpr int led4_pin = 10;
// buttons
constexpr int button1_pin = A1;
constexpr int button2_pin = A2;
constexpr int button3_pin = A3;
// trimmer
constexpr int trimmer_pin = A0;
// numerical digits for 7-segs
constexpr int digits[10] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90 };
constexpr int empty_glyph = 0xff;
#endif