Balboa32U4 library
Balboa32U4.h
Go to the documentation of this file.
1 // Copyright Pololu Corporation. For more information, see http://www.pololu.com/
2 
10 #pragma once
11 
12 #ifndef __AVR_ATmega32U4__
13 #error "This library only supports the ATmega32U4. Try selecting A-Star 32U4 in the Boards menu."
14 #endif
15 
16 #include <FastGPIO.h>
17 #include <Balboa32U4Buttons.h>
18 #include <Balboa32U4Buzzer.h>
19 #include <Balboa32U4Encoders.h>
20 #include <Balboa32U4LCD.h>
21 #include <Balboa32U4LineSensors.h>
22 #include <Balboa32U4Motors.h>
23 
24 // TODO: servo support
25 
33 inline void ledRed(bool on)
34 {
36 }
37 
41 inline void ledYellow(bool on)
42 {
44 }
45 
53 inline void ledGreen(bool on)
54 {
56 }
57 
66 inline bool usbPowerPresent()
67 {
68  return USBSTA >> VBUS & 1;
69 }
70 
75 inline uint16_t readBatteryMillivolts()
76 {
77  const uint8_t sampleCount = 8;
78  uint16_t sum = 0;
79  for (uint8_t i = 0; i < sampleCount; i++)
80  {
81  sum += analogRead(A1);
82  }
83 
84  // VBAT = 3 * millivolt reading = 3 * raw * 5000/1024
85  // = raw * 1875 / 128
86  // The correction term below makes it so that we round to the
87  // nearest whole number instead of always rounding down.
88  const uint32_t correction = 64 * sampleCount - 1;
89  return ((uint32_t)sum * 1875 + correction) / (128 * sampleCount);
90 }
static void setOutput(bool value) __attribute__((always_inline))
Sets the pin as an output.
Definition: FastGPIO.h:260
void ledGreen(bool on)
Turns the green user LED (TX) on or off.
Definition: Balboa32U4.h:53
uint16_t readBatteryMillivolts()
Reads the battery voltage and returns it in millivolts.
Definition: Balboa32U4.h:75
void ledRed(bool on)
Turns the red user LED (RX) on or off.
Definition: Balboa32U4.h:33
void ledYellow(bool on)
Turns the yellow user LED on pin 13 on or off.
Definition: Balboa32U4.h:41
bool usbPowerPresent()
Returns true if USB power is detected.
Definition: Balboa32U4.h:66