-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnergy.ino
70 lines (59 loc) · 1.53 KB
/
Energy.ino
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
/ energyUpdate
/ The energy increases here based on the distance since last measured.
*/
void energyUpdate()
{
// distance and energy updated based on position difference
new_distance = abs(position - new_position);
new_energy = energy + new_distance;
// update our measurements for a comparison next round
position = new_position;
distance = distance + new_distance;
energy = new_energy;
}
/*
/ energyDecay
/ A static energy decay that is called from the main loop.
*/
void energyDecay()
{
// is it less than it was since we last decayed?
if(debugging){
if ((energy + new_distance) < ((energy + new_distance) - cooling_amount * 2)) {
Serial.print("Too Slow!");
}
}
if (!outrunDecay() && energy > energy_levels[0]) {
if(nonono_playable) {
if(debugging){
Serial.println("Playing Encouragement.");
}
encouragement();
}
}
last_second_energy = energy;
// energy level decay
new_energy = energy + new_distance - cooling_amount;
// update our measurements for a comparison next round
energy = new_energy;
if (!stage[4]) {
if(debugging) { Serial.println("Ember decaying"); }
rampEmber();
}
if(debugging && stage[7]) {
Serial.print("Energy = ");
Serial.print(energy);
Serial.println();
}
}
/*
/ outrunDecay
/ Check if we're generating energy faster than the cooling amount.
*/
boolean outrunDecay() {
if ((energy - last_second_energy) > cooling_amount) {
return true;
}
return false;
}