Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit 961999b

Browse files
committed
Added IO expander.
1 parent 0d367ef commit 961999b

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

robot-control-src/board.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#include <Arduino.h>
33

44
namespace board {
5-
decltype(leftOdoSignal) leftOdoSignal;
6-
decltype(rightOdoSignal) rightOdoSignal;
7-
decltype(rightBackwards) rightBackwards;
8-
decltype(leftBackwards) leftBackwards;
9-
decltype(leftMotor) leftMotor = D1;
10-
decltype(rightMotor) rightMotor = D2;
11-
decltype(debugLed) debugLed = D0;
5+
constexpr std::uint8_t ioExpander1Address = 0x00;
6+
MCP23017 ioExpander1(ioExpander1Address);
7+
MCP23017Pin leftBackwards(ioExpander1, 8+0);
8+
MCP23017Pin rightBackwards(ioExpander1, 8+1);
9+
MCP23017Pin leftBumper(ioExpander1, 8+6);
10+
MCP23017Pin rightBumper(ioExpander1, 8+7);
1211
};

robot-control-src/board.hpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
#if !defined(BOARD_HPP)
22
#define BOARD_HPP
33
#include "DigitalPin.hpp"
4+
#include "MCP23017Pin.hpp"
45
#include <Arduino.h>
56
#include <cmath>
7+
#include <MCP23017.h>
68

79
typedef decltype(millis()) Milliseconds;
810
constexpr auto pi = std::acos(-1);
911

1012
namespace board
1113
{
12-
extern DigitalPin<D6> leftOdoSignal;
13-
extern DigitalPin<D5> rightOdoSignal;
14-
extern DigitalPin<D5> rightBackwards;
15-
extern DigitalPin<D5> leftBackwards;
16-
extern const std::uint8_t leftMotor;
17-
extern const std::uint8_t rightMotor;
18-
extern const std::uint8_t debugLed;
14+
constexpr std::uint8_t debugLed = D0;
15+
constexpr std::uint8_t leftMotor = D1;
16+
constexpr std::uint8_t rightMotor = D2;
17+
constexpr std::uint8_t scl = D3;
18+
constexpr std::uint8_t sda = D4;
19+
constexpr std::uint8_t rightOdoSignal = D5;
20+
constexpr std::uint8_t leftOdoSignal = D6;
21+
constexpr std::uint8_t ioExpanderIntB = D7;
22+
constexpr std::uint8_t ioExpanderIntAInv = D8;
23+
extern MCP23017 ioExpander1;
24+
extern MCP23017Pin leftBackwards;
25+
extern MCP23017Pin rightBackwards;
26+
extern MCP23017Pin leftBumper;
27+
extern MCP23017Pin rightBumper;
1928

2029
constexpr auto maxVelocity = 220; //!< [mm/s]
2130
constexpr float odoIntervalLength = 12*pi; //!< [mm]

robot-control-src/robot-control-src.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void setup()
8282
Serial.flush();
8383
delay(100);
8484
Serial.printf("\n begin program '%s'\n", __FILE__);
85+
board::ioExpander1.init();
8586
pinMode(board::debugLed, OUTPUT);
8687
digitalWrite(board::debugLed, LOW);
8788
drives::leftDrive.init();

0 commit comments

Comments
 (0)