Week 4 Flashcards

1
Q

programming language used and its issues

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

char and strings

A

single charcter of text, or a number between 0 and 255, strings ar a char type array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

functions

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

setup

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

loop

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

declarations

A

“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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

three main conventions for beautiful code

A
  • Documentation
  • Casing
  • Blocks / indentation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Documentation

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

three types of casing and when to use

A

*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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

when do you have badly organised code

A

when indenting is deeper then 4 levels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

keywords in loops

A
  • The “break” keyword can be used to break out of a loop prematurely
  • The “continue” keyword breaks the current iteration of the loop.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to use blocking vs non-blocking cells in a your code

A
  • General rule: use blocking code only in your setup().
  • General rule: only use non-blocking calls in your loop()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

when are delays suitable

A

only for initiation and throttling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

timing using system time

A

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()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

use switch statement

A

if there are many alternative statements for a conditional. use

switch(state)
case 1
case 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

short hand

A

a<b ? y:z
only used when initiating a based condition

17
Q

Statemachines

A
  • A state machine is a model of computation
  • It consists of states and transitions between states
  • It can only be in one state at a time
  • Very powerful, because self-explanatory
  • Code represents structure 1:1
  • Easy to debug
  • If you can draw your system as a flow chart, you can make it into a state machine
  • States define what your system does at a particular moment
  • Transitions define conditions for changing from one state to another
18
Q

How to declare statemachine

A

first declare the states and transistions, then add the states to the machiiene
then add transisions
and then tell loop to run the machine

19
Q

libraries (code seperation)

A

a library is essentially seperated code. allows to cut difficult tasks into easy chuncks, increases readability

20
Q

class

A

a class is the blueprint for creating objects, they can contain data and functions. they are self contained

21
Q

object

A
  • An Object is an initiation of a Class
  • The lifecycle of an Object starts with the
    execution of the (or one of the) constructor(s)
  • The lifecycle ends with a call to the
    (optional) destructor (~)
  • The constructor is like the Setup of the
    main sketch it prepares memory and variables.
  • The destructor is where you can free memory
22
Q

create your own libraries

A

reuse code in multiple projects, easy to acces to work and is maintainable