Disclaimer:
It’s been years since I looked at anything resembling programming. As I’m hyper-associative, my big challenge is immediately understanding the code, as my mind is firing off random questions, that can de-rail thinking.
I think the best is to look at it from multiple perspectives. For example, this whole deal about pin 13. The board has a hole for (digital) 13. The LED on the board is linked to pin 13 – I think. LED_BUILTIN is a constant for “13”, I think. I could enter: pinMode (13, OUTPUT); . What is VOID all about? Does “return something” not include the LED flashing?
See what I mean? My plan is to accommodate my natural tendency by following the program details from inventr, and also cross-reference with documentation from arduino.cc. When I see different ways of describing the same thing, it will start clicking together. My hope is that, over time, it will start sinking in and become easier. In my opinion, this is what active learning is all about. I will maintain engagement and interest by asking questions of curiosity, that are pertinent to current area of focus.
I could opt for just loading sketches, skipping over details unknown to me, and primarily focusing on whatever is the current topic, but I’ve found that catches up to me at some point (during troubleshooting, typically). I need understanding of all elements.
When I cross-reference to another site, I’ll place the URLs at the bottom within my REFERENCE section
Comment section:
I covered this topic in another post. There are two forms of comments, that originate from c programming:
- /* This is my comment, which can span multiple lines*/
- // This is my comment, which extends from the “//” to the end of the current line (useful for in-line documentation)
Note: I’m impressed with the documentation, included in the sketch, by inventr – it’s actually quite clear – on the 4th reading. LOL!
Pin 13 linked to LED on UNO board
For some reason I had some initial confusion with this. I think it’s because there is reference to a Pin 13, where you attach a wire from #13 to the breadboard and then to an LED. The UNO board also has a red LED. Now, my understanding is that I can (without attaching to the breadboard) reference Pin 13, and it’s going to the onboard red LED.
void setup() {
}
Q: What does void mean?
A: I’ll probably understand this more later, but it means that the program is not expected to return information.
In this sketch – it turns a light on and off.
One good analogy is that If I asked someone to turn a light off and on, and they came back saying that they happened to be in the bathroom at the time – that information (I didn’t know) – the bathroom – would be an example of data being returned to the function. I think…
The “setup” part means that this is run each time the unit is powered up, or if the button is pushed on the board
pinMode(LED_BUILTIN, OUTPUT);
Q: What does pinMode mean?
A: You can configure pins to be either input or output. This will make more sense later.
In this case, I want the Pin to do a mode – output something – LED lighting up.
Q: What is a constant?
A: A constant is a way of assigning something to a variable which is then uniform across entire code or within specific sections of code. The concept allows: uniformity; not having to remember the associated answer (in this case: 13); theoretically being able to uniformly changing the answer by just changing the constant value.
Q: Outputting to…:
A: Well… Pin 13 is associated with LED – so, the LED
void loop() {
}
Void meaning it doesn’t return anything. Loop – it loops forever
digitalWrite(LED_BUILTIN, HIGH);
I’ll understand more soon about volts, amps, etc soon.
For now, Pin 13 is a digital pin. I’m telling it to send to LED_BUILTIN (digital pin 13) 5 volts (High) to turn on the light (LED anode)
Voltage 5 volts
delay(1000);
This causes a timed delay – about a second
digitalWrite(LED_BUILTIN, LOW);
In this case, it’s turning off the flow of 5 volts to digital pin 13 (LED Anode)
delay(1000);
More delays – 1 second
Code (sketch) for Arduino – Blink
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino
model, check the Technical Specs of your board at:
https://www.arduino.cc/en/Main/Products
modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
modified 8 Sep 2016
by Colby Newman
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/
// 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
}
REFERENCE:
https://docs.arduino.cc/built-in-examples/basics/Blink/#schematic