Romi32U4 library
Romi32U4.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 <Romi32U4Buttons.h>
18 #include <Romi32U4Buzzer.h>
19 #include <Romi32U4Encoders.h>
20 #include <Romi32U4LCD.h>
21 #include <Romi32U4Motors.h>
22 
23 // TODO: servo support
24 
32 inline void ledRed(bool on)
33 {
35 }
36 
40 inline void ledYellow(bool on)
41 {
43 }
44 
52 inline void ledGreen(bool on)
53 {
55 }
56 
65 inline bool usbPowerPresent()
66 {
67  return USBSTA >> VBUS & 1;
68 }
69 
74 inline uint16_t readBatteryMillivolts()
75 {
76  const uint8_t sampleCount = 8;
77  uint16_t sum = 0;
78  for (uint8_t i = 0; i < sampleCount; i++)
79  {
80  sum += analogRead(A1);
81  }
82 
83  // VBAT = 3 * millivolt reading = 3 * raw * 5000/1024
84  // = raw * 1875 / 128
85  // The correction term below makes it so that we round to the
86  // nearest whole number instead of always rounding down.
87  const uint32_t correction = 64 * sampleCount - 1;
88  return ((uint32_t)sum * 1875 + correction) / (128 * sampleCount);
89 }
void ledYellow(bool on)
Turns the yellow user LED on pin 13 on or off.
Definition: Romi32U4.h:40
void ledRed(bool on)
Turns the red user LED (RX) on or off.
Definition: Romi32U4.h:32
static void setOutput(bool value) __attribute__((always_inline))
Sets the pin as an output.
Definition: FastGPIO.h:260
uint16_t readBatteryMillivolts()
Reads the battery voltage and returns it in millivolts.
Definition: Romi32U4.h:74
bool usbPowerPresent()
Returns true if USB power is detected.
Definition: Romi32U4.h:65
void ledGreen(bool on)
Turns the green user LED (TX) on or off.
Definition: Romi32U4.h:52