Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ESP32 #5

Merged
merged 3 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions TM1637.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ uint8_t TM1637::writeByte(uint8_t data)
// shift out data 8 bits LSB first
for (uint8_t i = 8; i > 0; i--)
{
digitalWrite(_clock, LOW);
digitalWrite(_data, data & 0x01);
digitalWrite(_clock, HIGH);
writeSync(_clock, LOW);
writeSync(_data, data & 0x01);
writeSync(_clock, HIGH);
data >>= 1;
}
digitalWrite(_clock, LOW);
digitalWrite(_data, HIGH);
digitalWrite(_clock, HIGH);

writeSync(_clock, LOW);
writeSync(_data, HIGH);
writeSync(_clock, HIGH);

// get ACKNOWLEDGE
pinMode(_data, INPUT);
Expand All @@ -216,20 +217,35 @@ uint8_t TM1637::writeByte(uint8_t data)

void TM1637::start()
{
digitalWrite(_clock, HIGH);
digitalWrite(_data, HIGH);
digitalWrite(_data, LOW);
digitalWrite(_clock, LOW);
writeSync(_clock, HIGH);
writeSync(_data, HIGH);
writeSync(_data, LOW);
writeSync(_clock, LOW);
}


void TM1637::stop()
{
digitalWrite(_clock, LOW);
digitalWrite(_data, LOW);
digitalWrite(_clock, HIGH);
digitalWrite(_data, HIGH);
writeSync(_clock, LOW);
writeSync(_data, LOW);
writeSync(_clock, HIGH);
writeSync(_data, HIGH);
}

void TM1637::writeSync(uint8_t pin, uint8_t val)
{
digitalWrite(pin, val);

#if defined(ESP32)
nanoDelay(2);
#endif

}

void TM1637::nanoDelay(uint16_t n)
{
volatile uint16_t i = n;
while (i--);
}

// -- END OF FILE --
3 changes: 3 additions & 0 deletions TM1637.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class TM1637
uint8_t writeByte(uint8_t data);
void start();
void stop();

void writeSync(uint8_t pin, uint8_t val);
void nanoDelay(uint16_t n);
};

// -- END OF FILE --