www.cutedigi.com     Call Us:  303-834-7832    Email Us:  sales at cutedigi.com

Quick Find:    
Search
    
Use keywords to find the product you are looking for.
Categories
.NET Micro Frameworks
3D printer
Arduino
Arduino Kits
Arduino Shields
Book
Breakout Board
Cables
Cellular
Component
Development Tools
DMX512
Drone
EL
Ethernet
FPGA
GPS
LCD
Lighting LED
Powerline Communication
Programmer/Emulator
Project Case
Prototyping
Python-On-A-Chip
Raspberry Pi
Robotics
Security and Spy Camera
Sensor
Services
Storage
Tools
Tracking
Video
Wireless
Featured more
Advanced Learning Kit for Arduino
Advanced Learning Kit for Arduino
 $49.00 
Specials more
ATWIN Quad-band GPRS/GSM Shield for Arduino
ATWIN Quad-band GPRS/GSM Shield for Arduino
 $49.00  $45.00 
pcDuino3: A20 Single Board Computer supports Arduino Programming
pcDuino3: A20 Single Board Computer supports Arduino Programming
 $77.00  $49.00 
LinkSprite JPEG Color Camera Serial UART Interface (TTL level)
LinkSprite JPEG Color Camera Serial UART Interface (TTL level)
 $44.00  $39.00 
CuHead Pro WiFi/Ethernet Shield with AirPlay/DLNA Audio
CuHead Pro WiFi/Ethernet Shield with AirPlay/DLNA Audio
 $55.90  $51.00 
WiFi  RedBack 1.0 -- Arduino  yellowjacket Compatible
WiFi RedBack 1.0 -- Arduino yellowjacket Compatible
 $75.00  $64.99 
Linker Kit for Raspberry Pi / pcDuino
Linker Kit for Raspberry Pi / pcDuino
 $29.00  $24.90 
  Top » Catalog » Arduino » Sensor KY010 Arduino sample Code
Sensor KY010 Arduino sample Code   by Patrick

 

/*

  Button

 

 Turns on and off a light emitting diode(LED) connected to digital  

 pin 13, when pressing a pushbutton attached to pin 2. 

 

 

 The circuit:

 * LED attached from pin 13 to ground 

 * pushbutton attached to pin 2 from +5V

 * 10K resistor attached to pin 2 from ground

 

 * Note: on most Arduinos there is already an LED on the board

 attached to pin 13.

 

 

 created 2005

 by DojoDave

 modified 28 Oct 2010

 by Tom Igoe

 

 This example code is in the public domain.

 

 http://www.arduino.cc/en/Tutorial/Button

 */

 

// constants won't change. They're used here to 

// set pin numbers:

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  13;      // the number of the LED pin

 

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

 

void setup() {

  // initialize the LED pin as an output:

  pinMode(ledPin, OUTPUT);      

  // initialize the pushbutton pin as an input:

  pinMode(buttonPin, INPUT);     

}

 

void loop(){

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);

 

  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) {     

    // turn LED on:    

    digitalWrite(ledPin, HIGH);  

  } 

  else {

    // turn LED off:

    digitalWrite(ledPin, LOW); 

  }

}

 

This article was published on Monday 09 January, 2012.
Current Reviews: 0  Write Review 
Tell a friend
Tell a friend about this article:     
Shopping Cart more
0 items
Articles
New Articles (0)
All Articles (82)
Android
Arduino (30)
DMX512 (1)
FPPA (3)
GPS (6)
Industry News (5)
Linux Port Tutorial TQ2440 (24)
MCU Zone (4)
Multitouch Display (2)
PCB/SMT Assembly Service (2)
Sensors (1)
Smart Home (4)
Cards Accepted
Cards We Accept