eBoard ๐Ÿ‰  โ‘ โ‘งโ‘จ
Written for SIA 2017/2018
eagle_SoccerBoard.h
Go to the documentation of this file.
1 #ifndef EAGLE_EBOARD_HELPLIB_SOCCERBOARD
2 #define EAGLE_EBOARD_HELPLIB_SOCCERBOARD
3 
28  struct SoccerBoard {
33  inline SoccerBoard(void);
34  //inline ~SoccerBoard(void) {}
35  #if EBOARD_USE_UTILITY > 0x0 or defined(__AVR_ATmega2560__) //won't shrink space... just speed things up
36 
44  inline void led(int idx,bool state);
52  inline void ledOn(int idx);
60  inline void ledOff(int idx);
66  inline void ledsOff(void);
72  inline void ledMeter(int);
73 
74  #endif
75  #if EBOARD_USE_UTILITY > 0x0
76  inline void /*bool*/ button(int);
79  inline void waitForButton(int);
80  #endif
81 
91  inline void motor(uint8_t id,int16_t val);
93  inline void motorsOff(void);
94  //ARDUINO UNO PINOUT
95  //D0,D1 => Bluetooth connection
96  //D4,D5 => MotorControl (D5: 980Hz)
97  //D10,D13 => SPI
98 
108  inline void power(optVAL_t id, bool state);
118  inline void powerOn(optVAL_t id);
128  inline void powerOff(optVAL_t id);
134  inline void sleep(uint16_t t);
140  inline void msleep(uint16_t t);
148  inline bool digital (optVAL_t id);
156  inline optVAL_t analog (optVAL_t id);
158  inline void reset(void); /* use crash-reset? =>*/ /* wdt_enable(WDTO_15MS); while(1) {} */
159  };
161  SoccerBoard::SoccerBoard(void) {}
162 
163  #if defined(__AVR_ATmega2560__)
164  inline void SoccerBoard::led(int idx, bool state) {writePin(13,state);}
165  void SoccerBoard::ledOn(int) {writePin(13,HIGH);}
166  void SoccerBoard::ledOff(int) {writePin(13,LOW);}
167  void SoccerBoard::ledsOff(void) {writePin(13,LOW);}
168  void SoccerBoard::ledMeter(int) {writePin(13,HIGH);}
169  #elif EBOARD_USE_UTILITY > 0x0
170  void SoccerBoard::led(int, bool) {}
171  void SoccerBoard::ledOn(int) {}
172  void SoccerBoard::ledOff(int) {}
173  void SoccerBoard::ledsOff(void) {}
174  void SoccerBoard::ledMeter(int) {}
175  #endif
176 
177  #if EBOARD_USE_UTILITY > 0x0
178  void SoccerBoard::button(int) {}
179  void SoccerBoard::waitForButton(int) {}
180  #endif
181 
182  void SoccerBoard::motor(uint8_t id,int16_t val) {
183  if(id==0&&(val>-256 && val < 256)) {setPin(PIN_MOTOR_DIR,val<0); writePWM(abs(val));}
184  else if(id>0&&id<3&&(val>-0 && val < 1024)) {_servoHandler.write((id-1),(val *600/1023 - 300));}
185  }
186  void SoccerBoard::motorsOff(void) {writePWM(0);}
187 
188  void SoccerBoard::reset(void) {
189  #if EBOARD_USE_RESET > 0x0
190  wdt_enable(WDTO_15MS);
191  for(;;) {}
192  #endif
193  }
194 
195  void SoccerBoard::power(optVAL_t id, bool state) {writePin(id,state);}
196  void SoccerBoard::powerOn(optVAL_t id) {this->power(id,1);}
197  void SoccerBoard::powerOff(optVAL_t id) {this->power(id,0);}
198  void SoccerBoard::sleep(uint16_t t) {delay(1000*t);}
199  void SoccerBoard::msleep(uint16_t t) {delay(t);}
200  bool SoccerBoard::digital (optVAL_t id) {return readPin(id);}
201  optVAL_t SoccerBoard::analog (optVAL_t id) {return readPin(id,0);}
203 #endif
void writePWM(optVAL_t val)
write a clamped pwm value to an output pin
SoccerBoard(void)
The constructor.
[COPY&PASTE] This is the SoccerBoard ghost struct :D
void powerOn(optVAL_t id)
Set the state of a certain D-pin to HIGH.
void reset(void)
Resets the Soccerboard if EBOARD_USE_RESET is set to true.
void sleep(uint16_t t)
Say goodnight!
void writePin(optVAL_t idx, bool val)
write a boolean state to an output pin
void msleep(uint16_t t)
Say goodnight!
void motorsOff(void)
As requested this is the shortcut to disable the main motor.
void motor(uint8_t id, int16_t val)
As requested this is the ultimate shortcut ;)
bool digital(optVAL_t id)
Reads a digital value from a pin.
void power(optVAL_t id, bool state)
Set the state of a certain D-pin.
optVAL_t readPin(optVAL_t idx, bool dig=true)
read a digital state from an INPUTpin
#define PIN_MOTOR_DIR
Definition: eBoard.h:420
optVAL_t analog(optVAL_t id)
Reads an analog value from a pin.
int optVAL_t
Definition: eBoard.h:196
void powerOff(optVAL_t id)
Set the state of a certain D-pin to LOW.