0% found this document useful (0 votes)
82 views

Const Int Const Int: Ledpin 13 Buttonpin 17

This code defines constants for an onboard LED connected to pin 13 and button connected to pin 17. It initializes the buttonState variable and sets the pin modes in setup. The main loop reads the buttonState, and if high, turns on the LED, while if low, turns off the LED, toggling the LED based on the button press.

Uploaded by

Andrew Tan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Const Int Const Int: Ledpin 13 Buttonpin 17

This code defines constants for an onboard LED connected to pin 13 and button connected to pin 17. It initializes the buttonState variable and sets the pin modes in setup. The main loop reads the buttonState, and if high, turns on the LED, while if low, turns off the LED, toggling the LED based on the button press.

Uploaded by

Andrew Tan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

code:

by DojoDave <http://www.0j0.org> modified 30 Aug 2011 by Tom Igoe


*/
/*
**************************************************************
Variable and Library declarations
**************************************************************
*/
// Constants:
const int ledPin = 13;// Built-in LED onboard is connected to pin 13
const int buttonPin = 17;// Built-in Button onboard is connected to pin 17

// Variables:
int buttonState = 0;

/*
**************************************************************
Pin and other Set-up Configuration
**************************************************************
*/
void setup()
{
// Initialize OUTPUTS

// Read the current state of the buttonPin


buttonState =digitalRead(buttonPin);
// Check if button is pushed
if (buttonState ==HIGH)
{
// Turn LED ON
digitalWrite(ledPin,HIGH);
}
else
{
// Turn LED OFF
digitalWrite(ledPin,LOW);
}
}

/*
**************************************************************
User Defined Functions
**************************************************************
*/

You might also like