5. Programming (2) Flashcards

1
Q

What are the 2 functions that Arduino gives us to place code?

A

setup() - anything you put here runs once at the start of the program
loop() - anything in here is run repeatedly. We will find that a loop is a very important part of a C program. setup and loop code go between curly brackets

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

What are the 3 sections in the Arduino template when a new C program is started?

A
  1. Initialisation (block)
  2. Setup
  3. Loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does this mean: ‘int led = 13;’?

A

Define a variable called led, which is an integer (4 byte, signed). =13 tells the compiler to initialise led with the value 13.

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

What does:
‘void setup() {
pinMode(led, OUTPUT);’ mean?

A

Set up the chosen pin led as an output. The function pinMode has been defined by arduino.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
what does: 'void loop() {
digitalWrite(led, HIGH);
delay(1000); 
digitalWrite(led, LOW); 
delay(1000); ' mean?
A

This makes the LED flash slowly. digitalWrite function writes to a digital pin which must have already been set up as an output. We can either make the pin high voltage (HIGH) or low voltage (LOW). The delay function takes a delay time in milliseconds.

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