Week 4 Flashcards
programming language used and its issues
C++, arduino does not understand so has to compile, this can cause syntax errors (does not compile) or runtime errors(compiled but did not run correcttly), which will only manifest itself when it is being ran
char and strings
single charcter of text, or a number between 0 and 255, strings ar a char type array
functions
a block of code that performs a single task.
functions define a return type ( a variable that is returned by the function), if ther eis no returned variable, the return type is void
functions can define required attributes
it can only be useed after it is defined
setup
- Reading the setup should tell you:
- The initial state of the program
- What systems are used by default
- What needs to be done before the system is ready
- Use functions for complex tasks (readability!)
- Use line breaks to divide code in clear units
- Use comments if it helps understanding the code
loop
- Loop just calls a bunch of functions
- Functions should be non-blocking
- Reading the loop should tell you:
- What the program does during normal operation.
- What tasks run in parallel
- What influences operation
- What function is available when
declarations
“The stuff at the top of your code files”
* Start with includes and defines
* Then variables
* Then class instantiations
* Then function declarations
* When reading a declaration you learn:
* What does a program require
* What are the settings
* How are things connected
three main conventions for beautiful code
- Documentation
- Casing
- Blocks / indentation
Documentation
Start your program file with a clear
comment.
* Add program name
* Describe its purpose
* Note down who wrote the program
* And: when it was written
* You can also add license and copyright
information here. Do you allow others
to use it, and if so under what
conditions?
* You can add links for more information
* Make sure to also document all
functions and variables
three types of casing and when to use
*lowerCamelCase is commonly used for:
* Variable names
* Class method names
* Function names
UpperCamelCase is commonly used for:
* Class names
* “global” functions
UPPER(SNAKE)CASE is commonly used for:
* Static constant variables (variables that do not change during the run of the program)
* Macro’s (#define
when do you have badly organised code
when indenting is deeper then 4 levels
keywords in loops
- The “break” keyword can be used to break out of a loop prematurely
- The “continue” keyword breaks the current iteration of the loop.
how to use blocking vs non-blocking cells in a your code
- General rule: use blocking code only in your setup().
- General rule: only use non-blocking calls in your loop()
when are delays suitable
only for initiation and throttling
timing using system time
For non-blocking timing System time can be used
* Arduino counts the process ticks since it was last powered up
* And calculates milliseconds or even microseconds since boot.
* These values are available through millis() and microSeconds()
use switch statement
if there are many alternative statements for a conditional. use
switch(state)
case 1
case 2