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 @@
.ds_store

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Hans
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,67 @@
# LEDbar Arduino library
A High level library for use with the Sure Electronics DE-DP011 40 segment LED bar, or any other 74HC164 based LED bar. This library makes it easy to interface this LED bar into your project. Make sure to check out [the examples](https://github.com/MCUdude/LEDbar/tree/master/examples) for getting the most out of this library!
<br/>
<img src="http://i.imgur.com/fAAerl4.jpg" width="400"> <img src="http://i.imgur.com/htIPYlU.jpg" width="400">
## Supported microcontrollers
Any Arduino compatible microcontroller with at least 2 IO pins! This library does not depend on hardware spesific code.
## How to install
This library can be installed in two ways, ether by using the manual mode or by using the Arduino library editor.
### Manual installation
Click on the "Clone or download" button in the upper right corner, and then "Download ZIP". Exctract the ZIP file, and move the extracted folder to the location "~/Documents/Arduino/libraries". Create the "libraries" folder if it doesn't exist. Open Arduino IDE, and a new library called "LEDbar" will show up under the "examples" menu.
### Library manager installation
The library is also available through Arduino's library manager. <br/>
To open the library manager, in the IDE click on `Sketch` -> `Include Library` -> `Manage Libraries` <br/>
Then search for <b>LEDbar</b>.
## About the LED bar
This LED bar was previously maufactured and sold by [Sure Electronics](http://store3.sure-electronics.com), and the user manual can be [downloaded here](https://github.com/MCUdude/LEDbar/raw/master/DE-DP011_Users_guide.pdf). The LED bar got 40 LEDs that's controlled by five [74HC164 serial-in parallel-out shift registers](http://www.nxp.com/documents/data_sheet/74HC_HCT164.pdf). The board also got a dim input, that can be pulsed in order to dim the LEDs.
<br/>
As the user manual states; the clock frequency can be no more than 10 MHz, and no more than 4 LED bars should be daisy chained to precent signaling issues.
<br/>
## Minimal setup
Here's a minimal setup that will get you up and running. Note that this setup includes the BUSY pin.
<br/> <br/>
<img src="http://i.imgur.com/e9aMiJV.png" width="430"> <img src="http://i.imgur.com/hEBoSiW.jpg" width="430">
## Reference
### Constructor
This library has two constructors, on with and one without the DIM pin. Using the DIM pin isn't mandatory, but it's recommended, because the LED bar will flash and blink while the bits are clocked out.
``` c++
// Constructor with dim pin
LEDbar(uint8_t clk, uint8_t data, uint8_t dim);
// Constructor without dim pin
LEDbar(uint8_t clk, uint8_t data);
```
### Methods
``` c++
// Pass the number of LEDs
void begin(uint8_t numberOfLEDs);
// Clear the LED bar
void clear();
// Turn on all LEDs
void all();
// Adjust the brightness (0 - 255)
void brightness(uint8_t level);
// Set n dots from position x
void setDots(uint8_t position, uint8_t dots);
// Turn on n leds from start position. Use negative numbers to start from the other end
void setLevel(int8_t level);
// Set a repeating pattern, 8 bit standard
void setPattern(uint64_t pattern, uint8_t length = 8);
```

View File

@@ -0,0 +1,113 @@
/*****************************************************************
| LEDbar Arduino library - based on the 74HC164 shift register |
| Developed and maintained by MCUdude |
| https://github.com/MCUdude/LEDbar |
| Released to the public domain |
| |
| Hello world! - A basic test program that shows the different |
| functionality in this library |
*****************************************************************/
// Include the library code
#include "LEDbar.h"
// Pin definitions
byte CLK = 5;
byte DATA = 6;
byte DIM = 7;
// Constants
const byte numberOfLEDs = 8; // My module has 40 LEDs
const byte commonDelay = 10; // Use the same delay everywhere
// Global variables
// Initialize the library with dim pin
//LEDbar led(CLK, DATA, DIM);
// Alternative without dim pin (tie the dimm pin on the LED bar to Vcc)
LEDbar led(CLK, DATA);
void setup()
{
// Initialize the LED bar with 40 LEDs
led.begin(numberOfLEDs);
// Set the brightness to 100 (8-bit --> 0 - 255)
//led.brightness(10);
}
void loop()
{
// Grow from 0 to 40 from left to right
for(uint8_t i = 0; i < numberOfLEDs; i++)
{
led.setLevel(i);
delay(commonDelay);
}
// Reduce from 40 to 0 from right to left
for(uint8_t i = numberOfLEDs; i > 0; i--)
{
led.setLevel(i);
delay(commonDelay);
}
// Grow from 0 to 40 from right to left
for(uint8_t i = 0; i < numberOfLEDs; i++)
{
// A minus indicates to start from the oposite side
led.setLevel(-i);
delay(commonDelay);
}
// Reduce from 40 to 0 from left to right
for(int8_t i = numberOfLEDs; i > -1; i--)
{
// A minus indicates to start from the oposite side
led.setLevel(-i);
delay(commonDelay);
}
// Short pause
delay(2000);
// Bounce back and forth, and grow each every time
for (uint8_t i = 1; i < numberOfLEDs; i++)
{
// Count up
for (uint8_t j = 0; j < numberOfLEDs - i; j++)
{
led.setDots(j, i); // (position, number of leds lit)
delay(commonDelay * 5); // Slow down a little
}
// Count down
for (int8_t j = numberOfLEDs - i; j > -1; j--)
{
led.setDots(j, i); // (position, number of leds lit)
delay(commonDelay * 5); // Slow down a little
}
}
// Set different repeating patterns
// Default length is 8 bit
led.setPattern(0b11110000);
delay(3000);
// Length 20 bit
//led.setPattern(0b11111000001111100000, 20);
//delay(3000);
// Length 40 bit
//led.setPattern(0b1111111011111100111110001111000011100000, 40);
//delay(3000);
// Clear all - fill with zeros
led.clear();
delay(1000);
}

View File

@@ -0,0 +1,55 @@
/*****************************************************************
| LEDbar Arduino library - based on the 74HC164 shift register |
| Developed and maintained by MCUdude |
| https://github.com/MCUdude/LEDbar |
| Released to the public domain |
| |
| VU meter example - Read analog pin A0 and display the level |
| on the LED bar. |
*****************************************************************/
// Include the library code
#include "LEDbar.h"
// Pin definitions
byte CLK = 5;
byte DATA = 4;
byte DIM = 3;
byte analogPin = A0;
// Constants
const byte numberOfLEDs = 40; // My module has 40 LEDs
// Global variables
byte vuData = 0;
// Initialize the library with dim pin
LEDbar led(CLK, DATA, DIM);
// Alternative without dim pin (tie the dimm pin on the LED bar to Vcc)
//LEDbar led(CLK, DATA);
void setup()
{
// Initialize the LED bar with 40 LEDs
led.begin(numberOfLEDs);
// Set the brightness to 100 (8-bit --> 0 - 255)
led.brightness(100);
}
void loop()
{
// Map the analog value (0 - 1023 steps) to fit the LED bar (0 - 40 steps)
vuData = map(analogRead(analogPin), 0, 1023, 0, numberOfLEDs);
// Display vuData on the LED bar
led.setLevel(vuData);
// Alternative way to run from the oposite direction
//led.setLevel(-vuData);
// Slow down a little
delay(5);
}

View File

@@ -0,0 +1,28 @@
#######################################
# Syntax Coloring Map for LEDbar
# (74HC164 based) library
# https://github.com/MCUdude/LEDbar
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
LEDbar KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
clear KEYWORD2
all KEYWORD2
brightness KEYWORD2
setDots KEYWORD2
setLevel KEYWORD2
setPattern KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

View File

@@ -0,0 +1,11 @@
name=LEDbar
version=1.0.0
author=MCUdude
maintainer=MCUdude
sentence=High level library for use with the Sure Electronics DE-DP011 40 segment LED bar (or any 74HC164 based LED bar)
paragraph=Written with speed in mind
category=Display
url=https://github.com/MCUdude/LEDbar
architectures=*
includes=LEDbar.h

View File

@@ -0,0 +1,106 @@
#include "Arduino.h"
#include "LEDbar.h"
// Constructor without dim pin
LEDbar::LEDbar(uint8_t clk, uint8_t data)
{
// Store to local variables
_clk = clk;
_data = data;
// Set clk, data and dim as output
pinMode(_clk, OUTPUT);
pinMode(_data, OUTPUT);
}
// Pass the number of LEDs
void LEDbar::begin(uint8_t numberOfLEDs)
{
_numberOfLEDs = numberOfLEDs;
}
// Clear the LED bar
void LEDbar::clear()
{
for(uint8_t i = 0; i < _numberOfLEDs; i++)
strobe(LOW);
}
// Turn on all LEDs
void LEDbar::all()
{
for(uint8_t i = 0; i < _numberOfLEDs; i++)
strobe(HIGH);
}
// Set n dots from position x
void LEDbar::setDots(uint8_t position, uint8_t dots)
{
// Turn LEDs off
uint8_t a = _numberOfLEDs;
// Shift out leading zeros
for (a; a > position + dots; a--)
strobe(LOW);
// Shift out ones
for (a; a > position; a--)
strobe(HIGH);
// Shift out tailing zeros
for (a; a > 0; a--)
strobe(LOW);
}
// Turn on n leds from start position. Use negative numbers to start from the other end
void LEDbar::setLevel(int8_t level)
{
// Turn LEDs off
if (level >= 0)
{
uint8_t a = _numberOfLEDs;
for (a; a > level; a--)
strobe(0);
for (a; a > 0; a--)
strobe(1);
}
else
{
int8_t a = -_numberOfLEDs;
for (a; a < -_numberOfLEDs - level; a++)
strobe(1);
for (a; a < 0; a++)
strobe(0);
}
}
// Set a repeating pattern, 8 bit standard
void LEDbar::setPattern(uint64_t pattern, uint8_t length)
{
// Shift out the bits
for(uint8_t i = 0; i < (_numberOfLEDs/length); i++)
{
for(uint8_t j = 0; j < length; j++)
strobe(bitRead(pattern, j));
}
}
// Latch bit
void LEDbar::strobe(bool dataIn)
{
digitalWrite(_data, dataIn);
digitalWrite(_clk, HIGH);
delayMicroseconds(10);
digitalWrite(_clk, LOW);
}

View File

@@ -0,0 +1,42 @@
#ifndef LEDbar_h
#define LEDbar_h
#include "Arduino.h"
class LEDbar
{
public:
// Constructor without dim pin
LEDbar(uint8_t clk, uint8_t data);
// Pass the number of LEDs
void begin(uint8_t numberOfLEDs);
// Clear the LED bar
void clear();
// Turn on all LEDs
void all();
// Set n dots from position x
void setDots(uint8_t position, uint8_t dots);
// Turn on n leds from start position. Use negative numbers to start from the other end
void setLevel(int8_t level);
// Set a repeating pattern, 8 bit standard
void setPattern(uint64_t pattern, uint8_t length = 8);
private:
// Latch bit
void strobe(bool dataIn);
/* Provate variables */
uint8_t _clk;
uint8_t _data;
uint8_t _numberOfLEDs;
};
#endif