-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
34 lines (26 loc) · 672 Bytes
/
utils.cpp
File metadata and controls
34 lines (26 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// Created by Allen on 2/11/2020.
//
#include "UART.h"
#include "metadata.h"
#include "animator.h"
#include "utils.h"
bool seedSet = false;
void sleep(uint32_t ms) {
uint32_t t1 = millis();
while(millis() - t1 < ms) {}
}
double absVal(double d) {
if(d < 0) return -d;
else return d;
}
// range of at most 100 because this rng sucks
int random(int low, int high) {
if(!seedSet) srand(millis());
int random = rand();
int toReturn = (random % 100) * (high - low + 1) / 99 + low;
// jank code to be safe and because i'm bad
if(toReturn < low) toReturn = low;
else if(toReturn > high) toReturn = high;
return toReturn;
}