Assignment:
This weeks assignment was an introduction to the programming of Arduino Boards.
Arduino’s are a type of PCB that can be used to control products internal or external electronics. They come in a variety of forms and can be customised with “Arduino Shields” for additional functionality. They do this via “Sketches” which is code used in the Arduino Environment. Thankfully, Arduino comes with plenty of example sketches which can be easily changed to suit your needs or preform different tasks.These can be accessed by clicking File>Example>01.Basic>Blink.
These sketches are made up of two parts, Void Setup(), which runs when the board is plugged in and Void Loop(), which will run in a loop over and over again until the board is disconnected.
This weeks documentation will cover 4 different sketches for the Arduino Environment, all stemming from the example “Blink”
Example Code: Blink
Blink is a very basic sketch which can be uploaded onto an Arduino Board without any changes. It makes the inbuilt LED flash once every 1000ms, or every one second. The code for this Sketch looks like this.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
To understand what you see here, remember these rules.
- Any line starting with // is not considered code by the compiler and will be skipped.
- { marks the beginning of the sketch and } marks the end.
- All lines of code must end with a ;
The final step is to press “Upload” with the Arduino connected to the PC and it will be loaded onto the board and continue forever.