5. Programming (2) Flashcards
What are the 2 functions that Arduino gives us to place code?
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
What are the 3 sections in the Arduino template when a new C program is started?
- Initialisation (block)
- Setup
- Loop
what does this mean: ‘int led = 13;’?
Define a variable called led, which is an integer (4 byte, signed). =13 tells the compiler to initialise led with the value 13.
What does:
‘void setup() {
pinMode(led, OUTPUT);’ mean?
Set up the chosen pin led as an output. The function pinMode has been defined by arduino.
what does: 'void loop() { digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); delay(1000); ' mean?
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.