Pololu3piPlus32U4 library
Pololu3piPlus32U4BumpSensors.h
Go to the documentation of this file.
1 // Copyright (C) Pololu Corporation. See www.pololu.com for details.
2 
4 
5 #pragma once
6 
7 #include <Arduino.h>
8 
9 namespace Pololu3piPlus32U4
10 {
11 
13 enum BumpSide {
15  BumpLeft = 0,
16 
18  BumpRight = 1
19 };
20 
24 {
25  public:
27  static const uint16_t defaultTimeout = 4000;
28 
29  static const uint8_t emitterPin = 11;
30  static const uint8_t bumpLeftPin = 4;
31  static const uint8_t bumpRightPin = 5;
32 
51  void calibrate(uint8_t count = 50);
52 
67  uint8_t read();
68 
73  bool leftChanged() { return (pressed[BumpLeft] ^ last[BumpLeft]) != 0; }
74 
75 
80  bool rightChanged() { return (pressed[BumpRight] ^ last[BumpRight]) != 0; }
81 
86  bool leftIsPressed() { return pressed[BumpLeft]; }
87 
92  bool rightIsPressed() { return pressed[BumpRight]; }
93 
100  uint16_t marginPercentage = 50;
101 
103  uint16_t baseline[2];
104 
106  uint16_t threshold[2];
107 
109  uint16_t sensorValues[2];
110 
113 
114  private:
115  void readRaw();
116  uint8_t pressed[2];
117  uint8_t last[2];
118 };
119 
120 }
Gets readings from the two bump sensors on the front of the 3pi+ 32U4.
uint16_t sensorValues[2]
Raw reflectance sensor readings.
bool leftChanged()
Indicates whether the left bump sensor's state has changed.
uint16_t threshold[2]
Thresholds for bump sensor press detection.
uint16_t marginPercentage
The amount, as a percentage, that will be added to the measured baseline to get the threshold.
uint16_t baseline[2]
Baseline readings obtained from calibration.
uint8_t read()
Reads both bump sensors.
bool rightIsPressed()
Indicates whether the right bump sensor is pressed.
bool leftIsPressed()
Indicates whether the left bump sensor is pressed.
uint16_t timeout
Timeout for bump sensor readings (in microseconds).
static const uint16_t defaultTimeout
Default timeout for RC sensors (in microseconds).
bool rightChanged()
Indicates whether the right bump sensor's state has changed.
void calibrate(uint8_t count=50)
Calibrates the bump sensors.
Top-level namespace for the Pololu3piPlus32U4 library.
@ BumpRight
Right bump sensor.