Giter VIP home page Giter VIP logo

exponentmap's Introduction

ExponentMap

Generates an exponentially growing array based on provided number of steps and maximum value.

Build Status release documentation license

The generated array can be used to control a PWM output perceived by humans (brigthness, sound...). Changing the power of an output device exponentially counteracts the logarithmic nature of the human perception.

The equation for generating the array is taken from Diarmuid.

Resources

Features

  • Configurable number of steps and max value.
  • Automatic calculation of optimum number of steps.

How it works

The first two plots demonstrate that a linearly changing output in time is perceived by a person logarithmically. And the second two plots demonstrate that an exponentially chaning output in time is perceived by a person linearly. plots

Example "exponent map":

Step Value
0 0
1 1
2 2
3 3
4 5
5 9
6 15
7 25
8 39
9 63
10 101
11 160
12 255

API

The library consists of a single class ExponentMap, which generates the array based on the parameters it was constructed with. The first parameter is the desired number of steps and the second is the maximum value. If the number of steps is not specified, the optimal number of steps will be calculated automatically.

ExponentMap<byte> exp1(12, 255);
ExponentMap<byte> exp2(255);

To get the value for a given step use the function operator. Alternatively the method stepToValue(step) can be used.

analogWrite(led, exp1(4));
analogWrite(led, exp1.stepToValue(4));

Basic example

#include "ExponentMap.h"

...

const byte led_pin = 3;
const byte pwm_max_value = 255;
byte steps_count = 12
byte current_step = 0;

ExponentMap<byte> e(steps_count, pwm_max_value);

...

void loop() {
  ...
  if (up_button == true) {
    analogWrite(led_pin, e(++current_step));
  }
  if (down_button == true) {
    analogWrite(led_pin, e(--current_step));
  }
  ...
}

License

The MIT License (MIT)

Copyright (c) 2016 Vasil Kalchev

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.

exponentmap's People

Contributors

njh avatar per1234 avatar thefedone avatar vasilkalchev avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

exponentmap's Issues

Not compiling in Arduino IDE 1.8.13

I'm a newbie. Wondering if I've got issues I need to work out, or if somethings changed w the Arduino IDE etc. I can not get the code to compile, regardless of board selected.

I'm probably doing something wrong. Please let me know if it compiles for you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.