Skip to content

Instantly share code, notes, and snippets.

@MargenauMaker
Created February 17, 2018 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MargenauMaker/ca57d12399db942d13e59ed3993f503e to your computer and use it in GitHub Desktop.
Save MargenauMaker/ca57d12399db942d13e59ed3993f503e to your computer and use it in GitHub Desktop.
/*
* modified from sparkfun tutorial
* by Ringotron5000
* modified for LilyMini
* by K Margenau
* 16 Feb 2018
******************************************************************************/
// Create integer variables for the pins we'll be using
int buttonPin = 2;
int buttonLED = 3;
void setup()
{
// Initialize the button pin as inputs with pullups.
// Pullups keep the inputs from "floating" when a button is unpressed.
pinMode(buttonPin, INPUT_PULLUP);
// Initialize the LED pins as outputs:
pinMode(buttonLED, OUTPUT);
}
void loop()
{
// This code will read the positions of the button,
// then use the "if" command to make LEDs follow these states.
// Create variables to store the button input values:
int buttonState;
// Read and save the states of the button:
buttonState = digitalRead(buttonPin);
// The if-else statement lets you do different things based on different inputs:
// The button will read as LOW when it's pressed
if (buttonState == LOW) // Check to see if buttonState is LOW (pressed)
{
digitalWrite(buttonLED,HIGH); // If buttonState is LOW (pressed), turn on the LED
}
else
{
digitalWrite(buttonLED,LOW); // If buttonState is HIGH (unpressed), turn off the LED
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment