-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
50 lines (42 loc) · 1005 Bytes
/
utils.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include "pins.h"
#include "constants.h"
inline static Point evalNewPoint(Point curPos, byte dir)
{
if (dir == Direction::up)
return Point{curPos.i - 1, curPos.j};
else if (dir == Direction::right)
return Point{curPos.i, curPos.j + 1};
else if (dir == Direction::down)
return Point{curPos.i + 1, curPos.j};
else if (dir == Direction::left)
return Point{curPos.i, curPos.j - 1};
return curPos;
}
inline static byte reverseb(byte start)
{
byte e = 0;
for (byte i = 0; i < 8; i++)
{
e = e << 1;
e |= ((start >> i) & 0x01);
}
return e;
}
inline static bool unblockingDelay(long *lastMillis, long delay)
{
if (millis() - *lastMillis < delay)
return false;
*lastMillis = millis();
return true;
}
inline static void playBuzzer(int t)
{
digitalWrite(Pin::buzzer, HIGH);
delay(t);
digitalWrite(Pin::buzzer, LOW);
}
inline static void initRandSeed()
{
randomSeed(analogRead(A5));
}