Arduino示例代码讲解:Project 13 - Touch Sensor Lamp 触摸传感灯

Arduino示例代码讲解:Project 13 - Touch Sensor Lamp 触摸传感灯

  • Project 13 - Touch Sensor Lamp 触摸传感灯
    • 程序功能概述
        • 功能:
        • 硬件要求:
        • 软件要求:
        • 输出:
    • 代码结构
        • 全局变量
        • `setup()` 函数
        • `loop()` 函数
        • 读取传感器值:
        • 打印传感器值:
        • 控制LED灯:
        • 延迟:
    • 运行过程
    • 注意事项

Project 13 - Touch Sensor Lamp 触摸传感灯

这段代码是一个Arduino程序,用于实现一个“触摸传感器灯”项目,通过一个电容式传感器检测触摸信号并控制一个LED灯的开关。

/*
  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
 http://arduino.cc/playground/Main/CapacitiveSensor

 Created 18 September 2012
 by Scott Fitzgerald

 http://arduino.cc/starterKit

 This example code is part of the public domain
 */

// import the library (must be located in the
// Arduino/libraries directory)
#include 

// 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

你可能感兴趣的:(从零开始学习机器人,单片机,机器人,人工智能,嵌入式硬件)