From 343935a4ab18e29de46f4cdde8c3d2c23b0fdb6f Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Mon, 13 Nov 2023 17:03:35 +0100 Subject: [PATCH] update readme.md (#26) - update readme.md - add ledbar example --- CHANGELOG.md | 6 +- MCP23S17.cpp | 2 +- MCP23S17.h | 4 +- README.md | 12 +++ .../MCP23S17_test_led_bar.ino | 81 +++++++++++++++++++ library.json | 4 +- library.properties | 2 +- 7 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c8c7e9..2111910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.7] - 2023-11-13 +- update readme.md +- add ledbar example + + ## [0.2.6] - 2023-08-15 - optimize 16 bit interface - add readReg16() + writeReg16() @@ -14,7 +19,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - update readme.md - minor edits - ## [0.2.5] - 2023-08-14 - add ESP32 HSPI / VSPI support (Kudo's to Alex Uta, PR #22) - add **performance_0.2.4.md** for ESP32 diff --git a/MCP23S17.cpp b/MCP23S17.cpp index 0263cda..3e38ebc 100644 --- a/MCP23S17.cpp +++ b/MCP23S17.cpp @@ -1,7 +1,7 @@ // // FILE: MCP23S17.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.6 +// VERSION: 0.2.7 // PURPOSE: Arduino library for SPI MCP23S17 16 channel port expander // DATE: 2021-12-30 // URL: https://github.com/RobTillaart/MCP23S17 diff --git a/MCP23S17.h b/MCP23S17.h index 4dcbe13..318185f 100644 --- a/MCP23S17.h +++ b/MCP23S17.h @@ -2,7 +2,7 @@ // // FILE: MCP23S17.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.6 +// VERSION: 0.2.7 // PURPOSE: Arduino library for SPI MCP23S17 16 channel port expander // DATE: 2021-12-30 // URL: https://github.com/RobTillaart/MCP23S17 @@ -13,7 +13,7 @@ #include "MCP23S17_registers.h" -#define MCP23S17_LIB_VERSION (F("0.2.6")) +#define MCP23S17_LIB_VERSION (F("0.2.7")) // ERROR CODES #define MCP23S17_OK 0x00 diff --git a/README.md b/README.md index c172c86..fb30121 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,11 @@ [![Arduino CI](https://github.com/RobTillaart/MCP23S17/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino-lint](https://github.com/RobTillaart/MCP23S17/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/MCP23S17/actions/workflows/arduino-lint.yml) [![JSON check](https://github.com/RobTillaart/MCP23S17/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/MCP23S17/actions/workflows/jsoncheck.yml) +[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/MCP23S17.svg)](https://github.com/RobTillaart/MCP23S17/issues) + [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/MCP23S17/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/MCP23S17.svg?maxAge=3600)](https://github.com/RobTillaart/MCP23S17/releases) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/MCP23S17.svg)](https://registry.platformio.org/libraries/robtillaart/MCP23S17) # MCP23S17 @@ -244,3 +247,12 @@ See examples. #### Wont +## Support + +If you appreciate my libraries, you can support the development and maintenance. +Improve the quality of the libraries by providing issues and Pull Requests, or +donate through PayPal or GitHub sponsors. + +Thank you, + + diff --git a/examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino b/examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino new file mode 100644 index 0000000..57f0041 --- /dev/null +++ b/examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino @@ -0,0 +1,81 @@ +// +// FILE: MCP23S17_test_led_bar.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo MCP23S17 control of LED bar +// URL: https://github.com/RobTillaart/MCP23S17 +// +// control of a 10-line LED bar, via pin 0..9 (Think VU meter etc) +// 2 different methods, one by one versus 16 bit mask +// bit mask is faster (~6x) for both HW SPI and SW SPI + + +#include "MCP23S17.h" +#include "SPI.h" + + +// MCP23S17 MCP(10, 12, 11, 13); // SW SPI address 0x00 +MCP23S17 MCP(10); // HW SPI address 0x00 + +uint32_t start, stop; + +void setup() +{ + Serial.begin(115200); + Serial.println(); + Serial.print("MCP23S17_LIB_VERSION: "); + Serial.println(MCP23S17_LIB_VERSION); + Serial.println(); + delay(100); + + SPI.begin(); + bool b = MCP.begin(); + Serial.println(b ? "true" : "false"); + + // all pins output + MCP.pinMode16(0x0000); // 0 = output, 1 = input + delay(100); +} + + +void loop() +{ + int x = analogRead(A0); // 0 .. 1023 + delay(100); + + start = micros(); + ledbar_1(x / 100); // 0 .. 10 + stop = micros(); + Serial.print("Time 1:\t"); + Serial.println(stop - start); + delay(1000); + + start = micros(); + ledbar_2(x / 100); // 0 .. 10 + stop = micros(); + Serial.print("Time 2:\t"); + Serial.println(stop - start); + Serial.println(); + delay(1000); +} + + +void ledbar_1(int x) +{ + // set leds one at a time. + int i = 0; + while (i++ < x) + { + MCP.digitalWrite(i, HIGH); + } + while (i++ < 10) MCP.digitalWrite(i, LOW); +} + + +void ledbar_2(int x) +{ + // use 16 bit bitmask. + uint16_t n = (1 << x) - 1; + MCP.write16(n); +} + +// -- END OF FILE -- diff --git a/library.json b/library.json index 9b42b5d..5ec08ef 100644 --- a/library.json +++ b/library.json @@ -15,9 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/MCP23S17.git" }, - "version": "0.2.6", + "version": "0.2.7", "license": "MIT", - "frameworks": "arduino", + "frameworks": "*", "platforms": "*", "headers": "MCP23S17.h" } diff --git a/library.properties b/library.properties index f8af1d4..650ab6d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=MCP23S17 -version=0.2.6 +version=0.2.7 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for SPI MCP23S17 16 channel port expander 16 IO-lines