-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino.h
90 lines (74 loc) · 1.84 KB
/
arduino.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef ARDUINO_H
#define ARDUINO_H
#include "const.h"
#include "ports.h"
#include <PWM.h>
class ArduinoControl : private PWM{
public:
enum TeamColor {
Blue = 0, Red = 1
};
enum LightsMode {
Off = 0,
Default = 1,
Disabled = 2,
Teleop = 3,
Autonomous = 4,
Test = 5,
WaitCatch = 6,
HasBall = 7
};
ArduinoControl(unsigned int pwmport, unsigned int colorport) : PWM(MAIN_SIDECAR, pwmport), mode(Default), color(false){
PWM::SetBounds(20.0, 10.0, 10.0, 10.0, 0.0);
PWM::SetPeriodMultiplier(PWM::kPeriodMultiplier_4X);
PWM::SetRaw(PWM::m_centerPwm);
colorchannel = new DigitalOutput(MAIN_SIDECAR, colorport);
update();
}
~ArduinoControl(){
//delete modechannel;
delete colorchannel;
}
void setMode(LightsMode newmode){
float oldmode = mode;
switch(newmode){
case Off:
case Default:
case Disabled:
mode = 0;
break;
case Teleop:
mode = 0.2;
break;
case Autonomous:
case Test:
mode = 0.4;
break;
case WaitCatch:
mode = -0.2;
break;
case HasBall:
mode = -0.4;
break;
}
if(oldmode != mode){
printf("Mode changed from %f to %f\n", oldmode, mode);
}
}
void setTeamColor(TeamColor newcolor){
color = (bool)newcolor;
}
void update(){
PWM::SetSpeed(mode);
colorchannel->Set(color);
}
// void setFlat(){
// //modechannel->SetRaw(PWM::m_centerPwm);
// }
private:
//PWM *modechannel;
DigitalOutput *colorchannel;
float mode;
bool color;
};
#endif // ARDUINO_H