source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 1.4 KB
Line 
1/*
2  Arduino Starter Kit example
3 Project 13  - Touch Sensor Lamp
4
5 This sketch is written to accompany Project 13 in the
6 Arduino Starter Kit
7
8 Parts required:
9 1 Megohm resistor
10 metal foil or copper mesh
11 220 ohm resistor
12 LED
13
14 Software required :
15 CapacitiveSensor library by Paul Badger
16 http://www.arduino.cc/playground/Main/CapacitiveSensor
17
18 Created 18 September 2012
19 by Scott Fitzgerald
20
21 http://www.arduino.cc/starterKit
22
23 This example code is part of the public domain
24 */
25
26// import the library (must be located in the
27// Arduino/libraries directory)
28#include <CapacitiveSensor.h>
29
30// create an instance of the library
31// pin 4 sends electrical energy
32// pin 2 senses senses a change
33CapacitiveSensor capSensor = CapacitiveSensor(4, 2);
34
35// threshold for turning the lamp on
36int threshold = 1000;
37
38// pin the LED is connected to
39const int ledPin = 12;
40
41
42void setup() {
43  // open a serial connection
44  Serial.begin(9600);
45  // set the LED pin as an output
46  pinMode(ledPin, OUTPUT);
47}
48
49void loop() {
50  // store the value reported by the sensor in a variable
51  long sensorValue = capSensor.capacitiveSensor(30);
52
53  // print out the sensor value
54  Serial.println(sensorValue);
55
56  // if the value is greater than the threshold
57  if (sensorValue > threshold) {
58    // turn the LED on
59    digitalWrite(ledPin, HIGH);
60  }
61  // if it's lower than the threshold
62  else {
63    // turn the LED off
64    digitalWrite(ledPin, LOW);
65  }
66
67  delay(10);
68}
69
70
71
Note: See TracBrowser for help on using the repository browser.