library ready

This commit is contained in:
fatimaxsen 2025-04-24 11:43:45 +03:00
parent 51cdbad841
commit db389802d8
8 changed files with 103 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 FABLAB BH
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.

17
README.md Normal file
View File

@ -0,0 +1,17 @@
# FABLAB_BH_Library
**Author:** Fatima Idrees
**Maintainer:** FABLAB BH
**License:** MIT
## Description
FABLAB_BH_Library is an Arduino library designed to [briefly describe what the library does, e.g., "control custom hardware developed at FABLAB BH"].
## Installation
1. Download the latest release from [GitHub/website].
2. In the Arduino IDE, go to **Sketch > Include Library > Add .ZIP Library...** and select the downloaded file.
## Usage

9
library.properties Normal file
View File

@ -0,0 +1,9 @@
name=FABLAB StripLED
version=1.0.0
author=Fatima
maintainer=FABLAB BH <contact@fablabbh.org>
sentence=Arduino library for FABLAB BH projects.
paragraph=This library provides useful functions for FABLAB BH hardware.
category= Communication
url=https://github.com/fablabbh/FABLAB_BH_Library
architectures=*

6
src/I2CCommands.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef I2C_COMMANDS_H
#define I2C_COMMANDS_H
#define CMD_CHANGE_ADDR 0xAA // Use the same value as in your slave
#endif

36
src/I2CMasterUtils.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "I2CMasterUtils.h"
#include "I2CCommands.h"
void I2CMasterUtils::scanI2C(Stream &output) {
output.println("Scanning for I2C devices...");
for (uint8_t addr = 1; addr < 127; addr++) {
Wire.beginTransmission(addr);
if (Wire.endTransmission() == 0) {
output.print("Found device at 0x");
output.println(addr, HEX);
}
}
}
void I2CMasterUtils::changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output) {
Wire.beginTransmission(oldAddr);
Wire.write(CMD_CHANGE_ADDR); // Use the command code from I2CCommands.h
Wire.write(newAddr);
Wire.endTransmission();
output.print("Sent address change command to 0x");
output.print(oldAddr, HEX);
output.print(" -> 0x");
output.println(newAddr, HEX);
}
bool I2CMasterUtils::parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr) {
if (!input.startsWith("ch")) return false;
int o, n;
int matched = sscanf(input.c_str(), "ch %x %x", &o, &n);
if (matched == 2) {
oldAddr = (uint8_t)o;
newAddr = (uint8_t)n;
return true;
}
return false;
}

14
src/I2CMasterUtils.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef I2CMASTERUTILS_H
#define I2CMASTERUTILS_H
#include <Arduino.h>
#include <Wire.h>
class I2CMasterUtils {
public:
static void scanI2C(Stream &output = Serial);
static void changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output = Serial);
static bool parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr);
};
#endif