feat: 全量同步 254 个常用的 Arduino 扩展库文件

This commit is contained in:
yczpf2019
2026-01-24 16:05:38 +08:00
parent c665ba662b
commit 397b9a23a3
6878 changed files with 2732224 additions and 1 deletions

View File

@@ -0,0 +1,263 @@
/*!
* @file Adafruit_MCP9808.cpp
*
* @mainpage Adafruit MCP9808 I2C Temp Sensor
*
* @section intro_sec Introduction
*
* I2C Driver for Microchip's MCP9808 I2C Temp sensor
*
* This is a library for the Adafruit MCP9808 breakout:
* http://www.adafruit.com/products/1782
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
* @section author Author
*
* K.Townsend (Adafruit Industries)
*
* @section license License
*
* BSD (see license.txt)
*
* @section HISTORY
*
* v1.0 - First release
*/
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#ifdef __AVR_ATtiny85__
#include "TinyWireM.h"
#define Wire TinyWireM
#else
#include <Wire.h>
#endif
#include "Adafruit_MCP9808.h"
/*!
* @brief Instantiates a new MCP9808 class
*/
Adafruit_MCP9808::Adafruit_MCP9808() {}
/*!
* @brief Setups the HW
* @param *theWire
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_MCP9808::begin(TwoWire *theWire) {
_wire = theWire;
_i2caddr = MCP9808_I2CADDR_DEFAULT;
return init();
}
/*!
* @brief Setups the HW
* @param addr
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_MCP9808::begin(uint8_t addr) {
_i2caddr = addr;
_wire = &Wire;
return init();
}
/*!
* @brief Setups the HW
* @param addr
* @param *theWire
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_MCP9808::begin(uint8_t addr, TwoWire *theWire) {
_i2caddr = addr;
_wire = theWire;
return init();
}
/*!
* @brief Setups the HW with default address
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_MCP9808::begin() {
_i2caddr = MCP9808_I2CADDR_DEFAULT;
_wire = &Wire;
return init();
}
/*!
* @brief init function
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_MCP9808::init() {
_wire->begin();
if (read16(MCP9808_REG_MANUF_ID) != 0x0054)
return false;
if (read16(MCP9808_REG_DEVICE_ID) != 0x0400)
return false;
write16(MCP9808_REG_CONFIG, 0x0);
return true;
}
/*!
* @brief Reads the 16-bit temperature register and returns the Centigrade
* temperature as a float.
* @return Temperature in Centigrade.
*/
float Adafruit_MCP9808::readTempC() {
float temp = NAN;
uint16_t t = read16(MCP9808_REG_AMBIENT_TEMP);
if (t != 0xFFFF) {
temp = t & 0x0FFF;
temp /= 16.0;
if (t & 0x1000)
temp -= 256;
}
return temp;
}
/*!
* @brief Reads the 16-bit temperature register and returns the Fahrenheit
* temperature as a float.
* @return Temperature in Fahrenheit.
*/
float Adafruit_MCP9808::readTempF() {
float temp = NAN;
uint16_t t = read16(MCP9808_REG_AMBIENT_TEMP);
if (t != 0xFFFF) {
temp = t & 0x0FFF;
temp /= 16.0;
if (t & 0x1000)
temp -= 256;
temp = temp * 9.0 / 5.0 + 32;
}
return temp;
}
/*!
* @brief Set Sensor to Shutdown-State or wake up (Conf_Register BIT8)
* @param sw true = shutdown / false = wakeup
*/
void Adafruit_MCP9808::shutdown_wake(boolean sw) {
uint16_t conf_shutdown;
uint16_t conf_register = read16(MCP9808_REG_CONFIG);
if (sw == true) {
conf_shutdown = conf_register | MCP9808_REG_CONFIG_SHUTDOWN;
write16(MCP9808_REG_CONFIG, conf_shutdown);
}
if (sw == false) {
conf_shutdown = conf_register & ~MCP9808_REG_CONFIG_SHUTDOWN;
write16(MCP9808_REG_CONFIG, conf_shutdown);
}
}
/*!
* @brief Shutdown MCP9808
*/
void Adafruit_MCP9808::shutdown() { shutdown_wake(true); }
/*!
* @brief Wake up MCP9808
*/
void Adafruit_MCP9808::wake() {
shutdown_wake(false);
delay(250);
}
/*!
* @brief Get Resolution Value
* @return Resolution value
*/
uint8_t Adafruit_MCP9808::getResolution() {
return read8(MCP9808_REG_RESOLUTION);
}
/*!
* @brief Set Resolution Value
* @param value
*/
void Adafruit_MCP9808::setResolution(uint8_t value) {
write8(MCP9808_REG_RESOLUTION, value & 0x03);
}
/*!
* @brief Low level 16 bit write procedures
* @param reg
* @param value
*/
void Adafruit_MCP9808::write16(uint8_t reg, uint16_t value) {
_wire->beginTransmission(_i2caddr);
_wire->write((uint8_t)reg);
_wire->write(value >> 8);
_wire->write(value & 0xFF);
_wire->endTransmission();
}
/*!
* @brief Low level 16 bit read procedure
* @param reg
* @return value
*/
uint16_t Adafruit_MCP9808::read16(uint8_t reg) {
uint16_t val = 0xFFFF;
uint8_t state;
_wire->beginTransmission(_i2caddr);
_wire->write((uint8_t)reg);
state = _wire->endTransmission();
if (state == 0) {
_wire->requestFrom((uint8_t)_i2caddr, (uint8_t)2);
val = _wire->read();
val <<= 8;
val |= _wire->read();
}
return val;
}
/*!
* @brief Low level 8 bit write procedure
* @param reg
* @param value
*/
void Adafruit_MCP9808::write8(uint8_t reg, uint8_t value) {
_wire->beginTransmission(_i2caddr);
_wire->write((uint8_t)reg);
_wire->write(value);
_wire->endTransmission();
}
/*!
* @brief Low level 8 bit read procedure
* @param reg
* @return value
*/
uint8_t Adafruit_MCP9808::read8(uint8_t reg) {
uint8_t val = 0xFF;
uint8_t state;
_wire->beginTransmission(_i2caddr);
_wire->write((uint8_t)reg);
state = _wire->endTransmission();
if (state == 0) {
_wire->requestFrom((uint8_t)_i2caddr, (uint8_t)1);
val = _wire->read();
}
return val;
}

View File

@@ -0,0 +1,82 @@
/*!
* @file Adafruit_MCP9808.h
*
* I2C Driver for Microchip's MCP9808 I2C Temp sensor
*
* This is a library for the Adafruit MCP9808 breakout:
* http://www.adafruit.com/products/1782
*
* Adafruit invests time and resources providing this open source code,
*please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
*
* BSD license (see license.txt)
*/
#ifndef _ADAFRUIT_MCP9808_H
#define _ADAFRUIT_MCP9808_H
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Wire.h>
#define MCP9808_I2CADDR_DEFAULT 0x18 ///< I2C address
#define MCP9808_REG_CONFIG 0x01 ///< MCP9808 config register
#define MCP9808_REG_CONFIG_SHUTDOWN 0x0100 ///< shutdown config
#define MCP9808_REG_CONFIG_CRITLOCKED 0x0080 ///< critical trip lock
#define MCP9808_REG_CONFIG_WINLOCKED 0x0040 ///< alarm window lock
#define MCP9808_REG_CONFIG_INTCLR 0x0020 ///< interrupt clear
#define MCP9808_REG_CONFIG_ALERTSTAT 0x0010 ///< alert output status
#define MCP9808_REG_CONFIG_ALERTCTRL 0x0008 ///< alert output control
#define MCP9808_REG_CONFIG_ALERTSEL 0x0004 ///< alert output select
#define MCP9808_REG_CONFIG_ALERTPOL 0x0002 ///< alert output polarity
#define MCP9808_REG_CONFIG_ALERTMODE 0x0001 ///< alert output mode
#define MCP9808_REG_UPPER_TEMP 0x02 ///< upper alert boundary
#define MCP9808_REG_LOWER_TEMP 0x03 ///< lower alert boundery
#define MCP9808_REG_CRIT_TEMP 0x04 ///< critical temperature
#define MCP9808_REG_AMBIENT_TEMP 0x05 ///< ambient temperature
#define MCP9808_REG_MANUF_ID 0x06 ///< manufacture ID
#define MCP9808_REG_DEVICE_ID 0x07 ///< device ID
#define MCP9808_REG_RESOLUTION 0x08 ///< resolutin
/*!
* @brief Class that stores state and functions for interacting with
* MCP9808 Temp Sensor
*/
class Adafruit_MCP9808 {
public:
Adafruit_MCP9808();
bool begin();
bool begin(TwoWire *theWire);
bool begin(uint8_t addr);
bool begin(uint8_t addr, TwoWire *theWire);
bool init();
float readTempC();
float readTempF();
uint8_t getResolution(void);
void setResolution(uint8_t value);
void shutdown_wake(boolean sw);
void shutdown();
void wake();
void write16(uint8_t reg, uint16_t val);
uint16_t read16(uint8_t reg);
void write8(uint8_t reg, uint8_t val);
uint8_t read8(uint8_t reg);
private:
TwoWire *_wire;
uint8_t _i2caddr;
};
#endif

View File

@@ -0,0 +1,18 @@
# Adafruit MCP9808 Library [![Build Status](https://github.com/adafruit/Adafruit_MCP9808_Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_MCP9808_Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_MCP9808_Library/html/index.html)
<a href="https://www.adafruit.com/product/1782"><img src="assets/board.jpg?raw=true" width="500px"></a>
This is the Adafruit MCP9808 Precision I2C Temperature sensor library
Tested and works great with the Adafruit MCP9808 Breakout Board
* http://www.adafruit.com/products/1782
This chip uses I2C to communicate, 2 pins are required to interface
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Kevin Townsend/Limor Fried for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
To install, use the Arduino Library Manager and search for "Adafruit MCP9808" and install the library.

View File

@@ -0,0 +1,127 @@
# Adafruit Community Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.
## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment
include:
* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities
Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an
open message from any channel, or a direct message to @kattni#1507,
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
@Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

View File

@@ -0,0 +1,69 @@
/**************************************************************************/
/*!
This is a demo for the Adafruit MCP9808 breakout
----> http://www.adafruit.com/products/1782
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include <Wire.h>
#include "Adafruit_MCP9808.h"
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
Serial.begin(9600);
while (!Serial); //waits for serial terminal to be open, necessary in newer arduino boards.
Serial.println("MCP9808 demo");
// Make sure the sensor is found, you can also pass in a different i2c
// address with tempsensor.begin(0x19) for example, also can be left in blank for default address use
// Also there is a table with all addres possible for this sensor, you can connect multiple sensors
// to the same i2c bus, just configure each sensor with a different address and define multiple objects for that
// A2 A1 A0 address
// 0 0 0 0x18 this is the default address
// 0 0 1 0x19
// 0 1 0 0x1A
// 0 1 1 0x1B
// 1 0 0 0x1C
// 1 0 1 0x1D
// 1 1 0 0x1E
// 1 1 1 0x1F
if (!tempsensor.begin(0x18)) {
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
while (1);
}
Serial.println("Found MCP9808!");
tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow:
// Mode Resolution SampleTime
// 0 0.5°C 30 ms
// 1 0.25°C 65 ms
// 2 0.125°C 130 ms
// 3 0.0625°C 250 ms
}
void loop() {
Serial.println("wake up MCP9808.... "); // wake up MCP9808 - power consumption ~200 mikro Ampere
tempsensor.wake(); // wake up, ready to read!
// Read and print out the temperature, also shows the resolution mode used for reading.
Serial.print("Resolution in mode: ");
Serial.println (tempsensor.getResolution());
float c = tempsensor.readTempC();
float f = tempsensor.readTempF();
Serial.print("Temp: ");
Serial.print(c, 4); Serial.print("*C\t and ");
Serial.print(f, 4); Serial.println("*F.");
delay(2000);
Serial.println("Shutdown MCP9808.... ");
tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
Serial.println("");
delay(200);
}

View File

@@ -0,0 +1,10 @@
name=Adafruit MCP9808 Library
version=1.1.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for the MCP9808 sensors in the Adafruit shop
paragraph=Arduino library for the MCP9808 sensors in the Adafruit shop
category=Sensors
url=https://github.com/adafruit/Adafruit_MCP9808_Library
architectures=*
depends=Adafruit Unified Sensor

View File

@@ -0,0 +1,26 @@
Software License Agreement (BSD License)
Copyright (c) 2012, Adafruit Industries
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.