diff --git a/TM1638x.cpp b/TM1638x.cpp index 45c8625..925295f 100644 --- a/TM1638x.cpp +++ b/TM1638x.cpp @@ -1,37 +1,40 @@ #include "Arduino.h" #include "TM1638x.h" #include "DIAG.h" +#include "IODevice.h" + // buttons K3/KS1-8 uint8_t TM1638x::getButtons(){ - digitalWrite(_stb_pin, LOW); + ArduinoPins::fastWriteDigital(_stb_pin, LOW); writeData(INSTRUCTION_READ_KEY); - //Twait 1µs pinMode(_dio_pin, INPUT); - digitalWrite(_clk_pin, LOW); - uint8_t data[4]; - for (uint8_t i=0; i>= 1; + ArduinoPins::fastWriteDigital(_clk_pin, HIGH); + ArduinoPins::fastWriteDigital(_clk_pin, LOW); + } } void TM1638x::writeDataAt(uint8_t displayAddress, uint8_t data){ - digitalWrite(_stb_pin, LOW); + ArduinoPins::fastWriteDigital(_stb_pin, LOW); writeData(displayAddress); writeData(data); - digitalWrite(_stb_pin, HIGH); + ArduinoPins::fastWriteDigital(_stb_pin, HIGH); delayMicroseconds(1); } void TM1638x::setDisplayMode(uint8_t displayMode){ - digitalWrite(_stb_pin, LOW); + ArduinoPins::fastWriteDigital(_stb_pin, LOW); writeData(displayMode); - digitalWrite(_stb_pin, HIGH); + ArduinoPins::fastWriteDigital(_stb_pin, HIGH); delayMicroseconds(1); } void TM1638x::setDataInstruction(uint8_t dataInstruction){ - digitalWrite(_stb_pin, LOW); + ArduinoPins::fastWriteDigital(_stb_pin, LOW); writeData(dataInstruction); - digitalWrite(_stb_pin, HIGH); + ArduinoPins::fastWriteDigital(_stb_pin, HIGH); delayMicroseconds(1); } @@ -107,11 +115,11 @@ void TM1638x::test(){ //setDisplayMode(DISPLAY_TURN_ON | _pulse); displayTurnOn(); setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_AUTO); - digitalWrite(_stb_pin, LOW); + ArduinoPins::fastWriteDigital(_stb_pin, LOW); writeData(FIRST_DISPLAY_ADDRESS); for(uint8_t i=0;i<16;i++) writeData(val); - digitalWrite(_stb_pin, HIGH); + ArduinoPins::fastWriteDigital(_stb_pin, HIGH); delay(1000); val = ~val; } diff --git a/TM1638x.h b/TM1638x.h index 6bbb23d..8218a14 100644 --- a/TM1638x.h +++ b/TM1638x.h @@ -38,17 +38,18 @@ class TM1638x{ private: - #define INSTRUCTION_WRITE_DATA 0x40 - #define INSTRUCTION_READ_KEY 0x42 - #define INSTRUCTION_ADDRESS_AUTO 0x40 - #define INSTRUCTION_ADDRESS_FIXED 0x44 - #define INSTRUCTION_NORMAL_MODE 0x40 - #define INSTRUCTION_TEST_MODE 0x48 + static const byte + INSTRUCTION_WRITE_DATA=0x40, + INSTRUCTION_READ_KEY=0x42, + INSTRUCTION_ADDRESS_AUTO=0x40, + INSTRUCTION_ADDRESS_FIXED=0x44, + INSTRUCTION_NORMAL_MODE=0x40, + INSTRUCTION_TEST_MODE=0x48, - #define FIRST_DISPLAY_ADDRESS 0xC0 + FIRST_DISPLAY_ADDRESS=0xC0, - #define DISPLAY_TURN_OFF 0x80 - #define DISPLAY_TURN_ON 0x88 + DISPLAY_TURN_OFF=0x80, + DISPLAY_TURN_ON=0x88; uint8_t _clk_pin;