In the second week, most of us had purchased an Arduino board, so we were ready to do some experiments. One of the more basic examples in Arduino’s “Sketchbook” is the “Blink” example.
The coding is quite short:
int ledPin = 13; // LED connected to digital pin 13
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
There are always two main parts of the programme. The first part (void setup()) states the pinModes and initialise the serial communication. The second part (void loop()) executes the programme.
It was not too difficult to do this first example and by successfully achieving it, we were more confident than before.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment