Zumo32U4 library
Zumo32U4.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 <Zumo32U4Buttons.h>
18 #include <Zumo32U4Buzzer.h>
19 #include <Zumo32U4Encoders.h>
20 #include <Zumo32U4IMU.h>
21 #include <Zumo32U4IRPulses.h>
22 #include <Zumo32U4LCD.h>
23 #include <Zumo32U4LineSensors.h>
24 #include <Zumo32U4Motors.h>
25 #include <Zumo32U4OLED.h>
27 
28 // TODO: servo support
29 
37 inline void ledRed(bool on)
38 {
39  FastGPIO::Pin<17>::setOutput(!on);
40 }
41 
45 inline void ledYellow(bool on)
46 {
47  FastGPIO::Pin<13>::setOutput(on);
48 }
49 
57 inline void ledGreen(bool on)
58 {
59  FastGPIO::Pin<IO_D5>::setOutput(!on);
60 }
61 
70 inline bool usbPowerPresent()
71 {
72  return USBSTA >> VBUS & 1;
73 }
74 
76 inline uint16_t readBatteryMillivolts()
77 {
78  const uint8_t sampleCount = 8;
79  uint16_t sum = 0;
80  for (uint8_t i = 0; i < sampleCount; i++)
81  {
82  sum += analogRead(A1);
83  }
84 
85  // VBAT = 2 * millivolt reading = 2 * raw * 5000/1024
86  // = raw * 625 / 64
87  // The correction term below makes it so that we round to the
88  // nearest whole number instead of always rounding down.
89  const uint32_t correction = 32 * sampleCount - 1;
90  return ((uint32_t)sum * 625 + correction) / (64 * sampleCount);
91 }
92 
void ledGreen(bool on)
Turns the green user LED (TX) on or off.
Definition: Zumo32U4.h:57
void ledYellow(bool on)
Turns the yellow user LED on pin 13 on or off.
Definition: Zumo32U4.h:45
uint16_t readBatteryMillivolts()
Reads the battery voltage and returns it in millivolts.
Definition: Zumo32U4.h:76
bool usbPowerPresent()
Returns true if USB power is detected.
Definition: Zumo32U4.h:70
void ledRed(bool on)
Turns the red user LED (RX) on or off.
Definition: Zumo32U4.h:37