Simple HC-SR04 ultrasonic distance sensor setup
This commit is contained in:
parent
eb7914190f
commit
ca31fcc1ed
11 changed files with 711 additions and 0 deletions
23
UltraSonic/dist/ShiftRegister.cpp
vendored
Normal file
23
UltraSonic/dist/ShiftRegister.cpp
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "ShiftRegister.h"
|
||||
|
||||
ShiftRegister::ShiftRegister(volatile uint8_t *shiftClockPort, uint8_t shiftClockPin,
|
||||
volatile uint8_t *dataPort, uint8_t dataPin,
|
||||
volatile uint8_t *latchClockPort, uint8_t latchClockPin)
|
||||
: m_shiftClockPin(shiftClockPort, shiftClockPin)
|
||||
, m_dataPin(dataPort, dataPin)
|
||||
, m_latchClockPin(latchClockPort, latchClockPin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ShiftRegister::output(int8_t value)
|
||||
{
|
||||
for (int8_t bitIdx = 7; bitIdx >= 0; --bitIdx)
|
||||
{
|
||||
m_dataPin.set(value & (1 << bitIdx));
|
||||
m_shiftClockPin.pulse();
|
||||
}
|
||||
|
||||
m_latchClockPin.pulse();
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue