Pololu3piPlus32U4 library
Pololu3piPlus32U4.h
Go to the documentation of this file.
1 // Copyright (C) Pololu Corporation. See www.pololu.com for details.
2 
8 
9 #pragma once
10 
11 #ifndef __AVR_ATmega32U4__
12 #error "This library only supports the ATmega32U4. Try selecting A-Star 32U4 in the Boards menu."
13 #endif
14 
15 #include <FastGPIO.h>
21 #include <Pololu3piPlus32U4LCD.h>
24 #include <Pololu3piPlus32U4OLED.h>
25 
28 {
29 
30 // TODO: servo support
31 
39 inline void ledRed(bool on)
40 {
41  FastGPIO::Pin<17>::setOutput(!on);
42 }
43 
47 inline void ledYellow(bool on)
48 {
49  FastGPIO::Pin<13>::setOutput(on);
50 }
51 
59 inline void ledGreen(bool on)
60 {
61  FastGPIO::Pin<IO_D5>::setOutput(!on);
62 }
63 
72 inline bool usbPowerPresent()
73 {
74  return USBSTA >> VBUS & 1;
75 }
76 
78 inline uint16_t readBatteryMillivolts()
79 {
80  const uint8_t sampleCount = 8;
81  uint16_t sum = 0;
82  for (uint8_t i = 0; i < sampleCount; i++)
83  {
84  sum += analogRead(A1);
85  }
86 
87  // VBAT = 3 * millivolt reading = 3 * raw * 5000/1024
88  // = raw * 1875 / 128
89  // The correction term below makes it so that we round to the
90  // nearest whole number instead of always rounding down.
91  const uint32_t correction = 64 * sampleCount - 1;
92  return ((uint32_t)sum * 1875 + correction) / (128 * sampleCount);
93 }
94 
95 }
Top-level namespace for the Pololu3piPlus32U4 library.
void ledGreen(bool on)
Turns the green user LED (TX) on or off.
uint16_t readBatteryMillivolts()
Reads the battery voltage and returns it in millivolts.
bool usbPowerPresent()
Returns true if USB power is detected.
void ledYellow(bool on)
Turns the yellow user LED on pin 13 on or off.
void ledRed(bool on)
Turns the red user LED (RX) on or off.