Hi there,
For me there is no any problem interfacing the 7-segment on TM1637 without using header file. But I am unable to interface the keyboard input. Can anyone suggest me, how to interface with the keyboard.
The program which i have used for display is as follows:
/* Program for Display on TM1637 */
const int clock = 2;
const int data = 3;
/0/ /1/ /2/ /3/ /4/ /5/ /6/ /7/ /8/ /9/
uint8_t digits[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
void setup()
{
pinMode(clock, OUTPUT);
pinMode(data, OUTPUT);
start();
writeValue(0x8c);
stop();
// clear display
write(0x00, 0x00, 0x00, 0x00);
}
void loop()
{
write(digits[1],digits[2],digits[3],digits[4]);
}
void write(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth)
{
start();
writeValue(0xc0);
writeValue(first);
writeValue(second);
writeValue(third);
writeValue(fourth);
stop();
}
void start(void)
{
digitalWrite(clock,HIGH);//send start signal to TM1637
digitalWrite(data,HIGH);
delayMicroseconds(5);
digitalWrite(data,LOW);
digitalWrite(clock,LOW);
delayMicroseconds(5);
}
void stop(void)
{
digitalWrite(clock,LOW);
digitalWrite(data,LOW);
delayMicroseconds(5);
digitalWrite(clock,HIGH);
digitalWrite(data,HIGH);
delayMicroseconds(5);
}
bool writeValue(uint8_t value)
{
for(uint8_t i = 0; i < 8; i++)
{
digitalWrite(clock, LOW);
delayMicroseconds(5);
digitalWrite(data, (value & (1 << i)) >> i);
delayMicroseconds(5);
digitalWrite(clock, HIGH);
delayMicroseconds(5);
}
// wait for ACK
digitalWrite(clock,LOW);
delayMicroseconds(5);
pinMode(data,INPUT);
digitalWrite(clock,HIGH);
delayMicroseconds(5);
bool ack = digitalRead(data) == 0;
pinMode(data,OUTPUT);
return ack;
}