Index

auto-plow / 90f6b37

A wheelchair motor-propelled battery-powered ESP32-driven remote control snow plow.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
630 Nov 2018 18:364a63c8cInclude Arduino core filesJoshua1580N

Blob @ auto-plow / include / arduino / WMath.cpp

text/plain1641 bytesdownload raw
1/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
3/*
4 Part of the Wiring project - http://wiring.org.co
5 Copyright (c) 2004-06 Hernando Barragan
6 Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General
19 Public License along with this library; if not, write to the
20 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 Boston, MA 02111-1307 USA
22*/
23
24extern "C" {
25 #include "stdlib.h"
26}
27
28void randomSeed(unsigned long seed)
29{
30 if (seed != 0) {
31 srandom(seed);
32 }
33}
34
35long random(long howbig)
36{
37 if (howbig == 0) {
38 return 0;
39 }
40 return random() % howbig;
41}
42
43long random(long howsmall, long howbig)
44{
45 if (howsmall >= howbig) {
46 return howsmall;
47 }
48 long diff = howbig - howsmall;
49 return random(diff) + howsmall;
50}
51
52long map(long x, long in_min, long in_max, long out_min, long out_max)
53{
54 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
55}
56
57unsigned int makeWord(unsigned int w) { return w; }
58unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }
59