GY-63_MS5611/libraries/MT8870/MT8870.cpp

62 lines
1.1 KiB
C++
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
// FILE: MT8870.cpp
// AUTHOR: Rob Tillaart
2021-12-22 05:05:27 -05:00
// VERSION: 0.1.4
2021-01-29 06:31:58 -05:00
// DATE: 2019-02-11
// PURPOSE: Arduino library for MT8870 DTMF decoder (breakout)
// URL: https://github.com/RobTillaart/MT8870
// https://www.tinytronics.nl/shop/nl/sensoren/geluid/mt8870-dtmf-module
//
2021-11-09 15:08:49 -05:00
2021-01-29 06:31:58 -05:00
#include "MT8870.h"
void MT8870::begin(uint8_t STQ, uint8_t Q1, uint8_t Q2, uint8_t Q3, uint8_t Q4)
{
_STQ = STQ;
_q[0] = Q1;
_q[1] = Q2;
_q[2] = Q3;
_q[3] = Q4;
for (uint8_t p = 0; p < 4; p++)
{
2021-11-09 15:08:49 -05:00
pinMode(_q[p], INPUT); // PULLUP ?
2021-01-29 06:31:58 -05:00
}
pinMode(_STQ, INPUT);
}
2021-11-09 15:08:49 -05:00
2021-01-29 06:31:58 -05:00
bool MT8870::available()
{
return (digitalRead(_STQ) == HIGH);
}
2021-11-09 15:08:49 -05:00
2021-01-29 06:31:58 -05:00
char MT8870::read()
{
uint8_t n = readRaw();
if (n < 16) return "D1234567890*#ABC"[n];
return 255;
}
2021-11-09 15:08:49 -05:00
2021-01-29 06:31:58 -05:00
uint8_t MT8870::readRaw()
{
_val = 255;
if (available())
{
_val = 0;
if (digitalRead(_q[0]) == HIGH) _val += 0x01;
if (digitalRead(_q[1]) == HIGH) _val += 0x02;
if (digitalRead(_q[2]) == HIGH) _val += 0x04;
if (digitalRead(_q[3]) == HIGH) _val += 0x08;
}
2021-11-09 15:08:49 -05:00
_lastTimeRead = millis();
2021-01-29 06:31:58 -05:00
return _val;
}
// -- END OF FILE --
2021-11-09 15:08:49 -05:00