Enhanced Precision with 10-Digit Input for parseFloat Function for MCUs
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Программирование микроконтроллеров
- Просмотров: 590
New Feature Update: Enhanced Precision with 10-Digit Input for parseFloat Function
The parseFloat function has been updated to handle up to 10 input digits. This enhancement ensures greater precision and flexibility in converting numeric strings to floating-point values, meeting the demands of more complex and extensive data processing tasks.
Key Improvements
1. Increased Input Range:
The function now accepts up to 10 numeric digits, a considerable upgrade from the previous limit of 6 digits. This increase allows for the conversion of larger numbers and supports applications requiring higher precision.
2. Robust Error Handling:
The updated function includes comprehensive error checking to ensure only valid numeric characters are processed. This prevents incorrect results caused by non-numeric characters in the input buffer.
3. Enhanced Flexibility:
With the capability to handle longer numeric strings, users can now input larger numbers without losing accuracy. This is particularly beneficial for financial calculations, scientific measurements, and other precision-critical applications.
Detailed Function Analysis
Here’s a closer look at the updated parseFloat function:
float parseFloat(uint8_t *buff, int symbols) {
// Ensure symbols is within the allowed range
if (symbols < 1 || symbols > 10) {
return 0.0; // or handle error appropriately
}
int64_t voltage = 0;
float mul = 1.0;
const uint32_t mulArr[11] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000};
if (*buff == 0x2D) { // Check for negative sign
mul = -1.0;
buff++;
symbols--;
}
while (symbols--) {
if (*buff < 0x30 || *buff > 0x39) { // Check for numeric characters
return 0.0; // or handle error appropriately
}
voltage += (*buff++ - 0x30) * mulArr[symbols];
}
return mul * (float)voltage / 100.0;
}
How It Works
1. Parameter Validation:
The function begins by verifying that the number of symbols is within the acceptable range (1 to 10). If not, it returns 0.0, indicating an error.
2. Negative Number Handling:
If the first character in the buffer is a minus sign (0x2D in ASCII), the function sets the multiplier mul to -1.0 to account for the negative value and moves the buffer pointer to the next character.
3. Character Conversion and Accumulation:
The function then processes each character in the buffer, ensuring they are numeric digits (ASCII values between 0x30 and 0x39).
It converts each character to its corresponding integer value, multiplies it by the appropriate factor from mulArr, and accumulates the result in voltage.
4. Final Calculation:
After processing all characters, the function returns the result as a floating-point number. The voltage is divided by 100.0 to adjust the decimal place, and it is multiplied by mul to handle any negative sign.
Benefits of the Update
- Higher Precision: With support for up to 10 digits, the function can now handle significantly larger numbers and more precise calculations.
- Error Resilience: The added checks for valid numeric characters ensure robust and accurate conversions, minimizing the risk of errors.
- Versatility: This enhancement makes the function suitable for a broader range of applications, from financial software to scientific research.
This update significantly enhances the usability and reliability of the parseFloat function. We look forward to seeing how our users leverage this new capability to achieve even greater precision and performance in their applications. As always, we welcome your feedback and suggestions for further improvements.
ANTIRTOS v0.1.3 Released: Introducing Delayed Function Execution Make It Super Easy And Fast
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Программирование микроконтроллеров
- Просмотров: 735
ANTIRTOS v0.1.3 Released: Introducing Delayed Function Execution
We are excited to announce the release of ANTIRTOS v0.1.3, now available on GitHub. This release introduces a powerful new feature: delayed function execution. This enhancement allows developers to schedule functions to be executed after a specified delay, simplifying the management of timed operations in IoT and embedded systems.
Key Feature: Delayed Function Execution
The delayed function execution feature in ANTIRTOS v0.1.3 provides a straightforward mechanism to schedule functions to run after a certain delay, measured in ticks. This is particularly useful for time-dependent tasks in IoT and embedded applications.
Initializing the Delayed Function Queue
To utilize the delayed function feature, initialize a delayed function queue as follows:
del_fQ F5(8); // Create a delayed queue with a capacity of 8
Adding Functions to the Queue
You can add functions to the delayed queue, specifying the delay in ticks. Here’s how you can schedule two functions with different delays:
F5.push_delayed(your_func_1, 1000); // Schedule your_func_1() to be executed after 1000 ticks
F5.push_delayed(your_func_2, 2000); // Schedule your_func_2() to be executed after 2000 ticks
Executing the Delayed Functions
In your main loop or any other periodic loop, call the pull method to execute the functions when their delay has elapsed. This function is highly efficient and can be executed quickly:
void loop() {
.......
F5.pull(); // Execute the scheduled functions
}
Tick Management
To manage the passage of ticks, call the tick method in a timer or another periodic function. This keeps the queue aware of the timing and ensures that functions are executed at the correct time:
F5.tick(); // Update the queue with the passage of ticks
Getting Started with ANTIRTOS v0.1.3
To explore the new delayed function execution feature and other improvements, visit the . The repository includes example projects.
git clone https://github.com/WeSpeakEnglish/ANTIRTOS.git
cd antirtos
Developers are encouraged to try out the new features, contribute to the project, and provide feedback.
About ANTIRTOS
ANTIRTOS is an ultra-lightweight, universal C++ library designed for task management in IoT and embedded applications. It is coded in a single, small file of just 5KB, making it incredibly easy to integrate into your projects. ANTIRTOS aims to deliver a robust, secure, and efficient platform for task management. With its focus on modularity and scalability, ANTIRTOS is suitable for a variety of devices, from simple microcontrollers to complex embedded systems.
Пара слайдеров на чистом HTML + Vanilla JS без использования input type = slider
- Информация о материале
- Автор: Super User
- Категория: Новости
- Просмотров: 795
<!DOCTYPE html>
<html>
<head>
<title>Linear Sliders</title>
<style>
.slider-container {
width: 300px;
margin: 20px auto;
text-align: center;
}
.slider {
width: 100%;
height: 30px;
position: relative;
background: linear-gradient(to right, darkblue, white, darkred);
margin-bottom: 20px;
}
.center-line {
position: absolute;
width: 2px;
height: 100%;
background-color: #000;
left: 50%;
top: 0;
}
.handle {
width: 10px;
height: 30px;
background-color: #000;
position: absolute;
cursor: pointer;
margin-left: -5px;
}
.value-input {
width: 60px;
font-size: 20px;
text-align: center;
}
</style>
</head>
<body>
<div id="slider1-container" class="slider-container">
<div id="slider1" class="slider">
<div class="center-line"></div>
<div id="handle1" class="handle"></div>
</div>
<input type="number" id="value1-input" class="value-input" step="0.1" value="0.0">
</div>
<div id="slider2-container" class="slider-container">
<div id="slider2" class="slider">
<div class="center-line"></div>
<div id="handle2" class="handle"></div>
</div>
<input type="number" id="value2-input" class="value-input" step="0.1" value="0.0">
</div>
<script>
function initializeSlider(sliderId, handleId, inputId) {
var slider = document.getElementById(sliderId);
var handle = document.getElementById(handleId);
var valueInput = document.getElementById(inputId);
function setHandlePosition(value) {
var sliderRect = slider.getBoundingClientRect();
var newLeft = ((value + 60) / 120) * sliderRect.width;
handle.style.left = newLeft + 'px';
}
// Initial handle position
setHandlePosition(0);
handle.onmousedown = function(event) {
event.preventDefault();
document.onmousemove = function(event) {
var sliderRect = slider.getBoundingClientRect();
var newLeft = event.clientX - sliderRect.left;
if (newLeft < 0) newLeft = 0;
if (newLeft > sliderRect.width) newLeft = sliderRect.width;
handle.style.left = newLeft + 'px';
var value = ((newLeft / sliderRect.width) * 120 - 60).toFixed(1);
valueInput.value = value;
};
document.onmouseup = function() {
document.onmousemove = null;
document.onmouseup = null;
};
};
valueInput.onchange = function() {
var value = parseFloat(valueInput.value);
if (isNaN(value)) {
value = 0;
}
if (value < -60) value = -60;
if (value > 60) value = 60;
setHandlePosition(value);
};
}
initializeSlider('slider1', 'handle1', 'value1-input');
initializeSlider('slider2', 'handle2', 'value2-input');
</script>
</body>
</html>
Combining E24 resistors to get best match in gain of inverting and non-inverting amplifiers: python
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Программирование
- Просмотров: 608
- E24 Resistor Series: Defines the standard E24 resistor values and scales them to a wide range of standard resistor values.
- Helper Functions: Functions to calculate series and parallel resistances, find the closest resistor value, and find resistor combinations.
- Inverting Amplifier Calculation: Calculates the necessary resistors for an inverting amplifier based on the desired gain, and checks for the best resistor combinations.
- Non-Inverting Amplifier Calculation: Calculates the necessary resistors for a non-inverting amplifier based on the desired gain, and checks for the best resistor combinations.
- Main Execution: Takes the desired gain as input, calculates the necessary resistors for both inverting and non-inverting amplifiers, and prints the results, including the calculated gain based on the selected resistors.
#inverting opamp: Uout = -(Rf / Rin)*Uin
#non inverting: Vout = (1 + Rf/Rin)*Vin
import itertools
import numpy as np
# Define E24 series resistors
E24_values = np.array([
1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0,
3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1
])
# Scale E24 values to standard resistor range
E24_resistors = np.unique([round(r * (10 ** exp), 1) for r in E24_values for exp in range(0, 7)])
# Helper functions to calculate series and parallel resistances
def series_resistance(resistors):
return sum(resistors)
def parallel_resistance(resistors):
return 1.0 / sum(1.0 / r for r in resistors)
# Function to find closest E24 resistor value
def closest_resistor(target, resistors):
return min(resistors, key=lambda x: abs(x - target))
# Function to find resistor combinations
def find_resistor_combination(target_resistance, resistors, max_combinations=2, tolerance=0.1):
# Check if single resistor is close enough
closest = closest_resistor(target_resistance, resistors)
if abs(closest - target_resistance) < tolerance:
return [closest], "single"
# Check combinations of up to max_combinations resistors in series
for n in range(2, max_combinations + 1):
for combination in itertools.combinations_with_replacement(resistors, n):
if abs(series_resistance(combination) - target_resistance) < tolerance:
return list(combination), "series"
# Check combinations of up to max_combinations resistors in parallel
for n in range(2, max_combinations + 1):
for combination in itertools.combinations_with_replacement(resistors, n):
if abs(parallel_resistance(combination) - target_resistance) < tolerance:
return list(combination), "parallel"
return [], "none"
# Function to calculate resistors for inverting amplifier
def calculate_inverting_resistors(gain):
R1_value = 10.0
R_f_value = R1_value * gain
R_f_combination, R_f_type = find_resistor_combination(R_f_value, E24_resistors)
R1_combination, R1_type = find_resistor_combination(R1_value, E24_resistors)
final_R_f_value = series_resistance(R_f_combination) if R_f_type == "series" else parallel_resistance(R_f_combination)
final_R1_value = series_resistance(R1_combination) if R1_type == "series" else parallel_resistance(R1_combination)
calculated_gain = final_R_f_value / final_R1_value
return {
"gain": gain,
"calculated_gain": calculated_gain,
"R_f": {"value": final_R_f_value, "combination": R_f_combination, "type": R_f_type},
"R1": {"value": final_R1_value, "combination": R1_combination, "type": R1_type}
}
# Function to calculate resistors for non-inverting amplifier
def calculate_non_inverting_resistors(gain):
R1_value = 10.0
R_f_value = R1_value * (gain - 1)
R_f_combination, R_f_type = find_resistor_combination(R_f_value, E24_resistors)
R1_combination, R1_type = find_resistor_combination(R1_value, E24_resistors)
final_R_f_value = series_resistance(R_f_combination) if R_f_type == "series" else parallel_resistance(R_f_combination)
final_R1_value = series_resistance(R1_combination) if R1_type == "series" else parallel_resistance(R1_combination)
calculated_gain = 1 + (final_R_f_value / final_R1_value)
return {
"gain": gain,
"calculated_gain": calculated_gain,
"R_f": {"value": final_R_f_value, "combination": R_f_combination, "type": R_f_type},
"R1": {"value": final_R1_value, "combination": R1_combination, "type": R1_type}
}
# Input gain
gain = float(input("Enter the desired gain: "))
# Calculate resistors for inverting and non-inverting amplifiers
inverting_result = calculate_inverting_resistors(gain)
non_inverting_result = calculate_non_inverting_resistors(gain)
# Output the result for both inverting and non-inverting configurations
print(f"Desired Gain: {gain}")
print("\nInverting Amplifier:")
print(f"Calculated Gain: {inverting_result['calculated_gain']:.2f}")
print(f"Feedback Resistor (R_f) value: {inverting_result['R_f']['value']} ohms")
print(f"R_f combination: {inverting_result['R_f']['combination']} ({inverting_result['R_f']['type']})")
print(f"Input Resistor (R1) value: {inverting_result['R1']['value']} ohms")
print(f"R1 combination: {inverting_result['R1']['combination']} ({inverting_result['R1']['type']})")
print("\nNon-Inverting Amplifier:")
print(f"Calculated Gain: {non_inverting_result['calculated_gain']:.2f}")
print(f"Feedback Resistor (R_f) value: {non_inverting_result['R_f']['value']} ohms")
print(f"R_f combination: {non_inverting_result['R_f']['combination']} ({non_inverting_result['R_f']['type']})")
print(f"Ground Resistor (R1) value: {non_inverting_result['R1']['value']} ohms")
print(f"R1 combination: {non_inverting_result['R1']['combination']} ({non_inverting_result['R1']['type']})")
kolecka do sprhy
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Жизнь
- Просмотров: 566
https://www.temu.com/ul/kuiper/un9.html?subj=goods-un&_bg_fs=1&_p_jump_id=894&_x_vst_scene=adg&goods_id=601099519016390&sku_id=17592226812693&adg_ctx=a-06b53c7d~c-c14a7b45~f-a052c1d3&_x_ads_sub_channel=shopping&_p_rfs=1&_x_ns_prz_type=3&_x_ns_sku_id=17592226812693&mrk_rec=1&_x_ads_channel=google&_x_gmc_account=5076073857&_x_login_type=Google&_x_ads_account=6799709807&_x_ads_set=20588780596&_x_ads_id=152615004694&_x_ads_creative_id=675137739977&_x_ns_source=g&_x_ns_gclid=CjwKCAjwjqWzBhAqEiwAQmtgT0xPHEfEEOId7sbXMare9ImDTub5AqwcaBVs7Oww96GgJeDv3lV47BoCGpkQAvD_BwE&_x_ns_placement=&_x_ns_match_type=&_x_ns_ad_position=&_x_ns_product_id=17592226812693&_x_ns_target=&_x_ns_devicemodel=&_x_ns_wbraid=Cj8KCQjw65-zBhCqARIuAIi9DfEGvetfutj8xiJBQ5Mg5tk0_Wa4uFY0ymriBPq17vnUYF40hiHuZLGWwxoCtIE&_x_ns_gbraid=0AAAAAo4mICFn9dUP2q6rxps22WGmrjtXH&_x_ns_targetid=pla-2201593715676&gad_source=1&gclid=CjwKCAjwjqWzBhAqEiwAQmtgT0xPHEfEEOId7sbXMare9ImDTub5AqwcaBVs7Oww96GgJeDv3lV47BoCGpkQAvD_BwE
https://allegro.cz/nabidka/kolecka-pro-sprchovou-kabinu-kolecka-sada-kolecka-valecek-sprchove-kabiny-14686197526?utm_feed=712e6653-4749-4512-b084-b6e297fc9e0b&utm_source=google&utm_medium=cpc&utm_campaign=CZ%3EHome%3EP%26S%3EPMAX&ev_campaign_id=20751747990&gad_source=1&gclid=CjwKCAjwjqWzBhAqEiwAQmtgTytnGX9nCIsm0mdaRMbqEDA5qilf4MwCDuUROJi9R7gD22kY9ah1ohoC3tcQAvD_BwE
https://allegro.cz/nabidka/dvojita-role-sprchovych-koutu-26-mm-12179237270?utm_feed=712e6653-4749-4512-b084-b6e297fc9e0b&utm_source=google&utm_medium=cpc&utm_campaign=CZ%3EHome%3EBathroom%3E3P%3EPMAX&ev_campaign_id=20027777979&gad_source=1&gclid=CjwKCAjwjqWzBhAqEiwAQmtgT-vy6rmaPSMwjr-nnw7z8EuZb6qVkaMWrVXXYwRoMdCF0-AuQn6YYBoCmKAQAvD_BwE
Страница 19 из 193
