Arduino-Development / examples /10.StarterKit_BasicKit /p13_TouchSensorLamp /p13_TouchSensorLamp.ino
Download examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino from Beifengdo/Arduino-Development: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/datasets/Beifengdo/Arduino-Development/resolve/main/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino
- Command line
-
hf download hf://datasets/Beifengdo/Arduino-Development/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino
-
curl -L -o p13_TouchSensorLamp.ino https://huggingface.co/datasets/Beifengdo/Arduino-Development/resolve/main/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino
1.49 kB
| /* | |
| Arduino Starter Kit example | |
| Project 13 - Touch Sensor Lamp | |
| This sketch is written to accompany Project 13 in the Arduino Starter Kit | |
| Parts required: | |
| - 1 megohm resistor | |
| - metal foil or copper mesh | |
| - 220 ohm resistor | |
| - LED | |
| Software required : | |
| - CapacitiveSensor library by Paul Badger | |
| https://www.arduino.cc/reference/en/libraries/capacitivesensor/ | |
| created 18 Sep 2012 | |
| by Scott Fitzgerald | |
| https://store.arduino.cc/genuino-starter-kit | |
| This example code is part of the public domain. | |
| */ | |
| // import the library (must be located in the Arduino/libraries directory) | |
| // create an instance of the library | |
| // pin 4 sends electrical energy | |
| // pin 2 senses senses a change | |
| CapacitiveSensor capSensor = CapacitiveSensor(4, 2); | |
| // threshold for turning the lamp on | |
| int threshold = 1000; | |
| // pin the LED is connected to | |
| const int ledPin = 12; | |
| void setup() { | |
| // open a serial connection | |
| Serial.begin(9600); | |
| // set the LED pin as an output | |
| pinMode(ledPin, OUTPUT); | |
| } | |
| void loop() { | |
| // store the value reported by the sensor in a variable | |
| long sensorValue = capSensor.capacitiveSensor(30); | |
| // print out the sensor value | |
| Serial.println(sensorValue); | |
| // if the value is greater than the threshold | |
| if (sensorValue > threshold) { | |
| // turn the LED on | |
| digitalWrite(ledPin, HIGH); | |
| } | |
| // if it's lower than the threshold | |
| else { | |
| // turn the LED off | |
| digitalWrite(ledPin, LOW); | |
| } | |
| delay(10); | |
| } | |