Created
May 16, 2018 18:46
-
-
Save jrheard/33350058e2395d3b181b08cc24021ae9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's write a program that blinks an LED on and off forever! | |
// An Arduino program always has two main parts: setup() and loop(). | |
// setup() is a function that gets run a single time at the start of the program. | |
// We usually use it to do "initialization", which basically means "stuff | |
// we have to do at the start of the program so that the rest of the program works right." | |
void setup() { | |
// In this program, the only initialization we need to do is this line: | |
pinMode(A0, OUTPUT); | |
// That line tells the Arduino system that our program will be using pin A0 as an _output_. | |
////// Pin numbers | |
// A0 is the pin that our LED is attached to. | |
// If your LED is attached to a different pin, then either move it to pin A0, | |
// or change the pinMode() line to refer to the right pin (e.g. pin A3 or whatever). | |
////// Input vs output | |
// Your program can use any pin as either an "input" or an "output". | |
// Inputs are things like sensors. When you use sensors, you attach them to your | |
// Arduino and then you write code that checks the value of the sensors - | |
// in this way, your program can figure out e.g. what the current temperature is. | |
// Inputs are things that your program _reads from_. | |
// Outputs are things like LEDs, or speakers, or motors. | |
// Outputs are thing that your program _controls_. | |
} | |
// loop() is a function that gets run over and over again until you turn your Arduino off. | |
// If you want your program to do something over and over again, you'll want to put that code in loop(). | |
void loop() { | |
// Let's start by turning the LED on! | |
// This line of code sets pin A0's voltage level to "high", which causes the LED to light up. | |
digitalWrite(A0, HIGH); | |
// Now let's wait for a second before we turn the LED off again. | |
delay(1000); | |
// delay() is a function that takes a number of milliseconds and pauses the program | |
// for that long - so if I write delay(500), the program will stop doing anything | |
// for 0.5 seconds. | |
// Now let's turn the LED off by setting its voltage level to "low"... | |
digitalWrite(A0, LOW); | |
// ...and then let's wait for another second. | |
delay(1000); | |
// After this delay(1000) call is done, this loop() function is over. | |
// But the Arduino system will automatically run it again, over and over, until you turn off your Arduino! | |
// That's why the light will keep blinking on and off. Does that make sense? | |
} | |
// That's it, that's the whole program! | |
// To make the light blink faster or slower, try changing the number your program passes to delay()! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment