2021-10-28 04:02:41 -04:00
|
|
|
//
|
|
|
|
// FILE: TM1637_alpha.ino
|
|
|
|
// AUTHOR: William F. Dudley Jr.
|
|
|
|
// VERSION: 0.1.0
|
|
|
|
// PURPOSE: demo TM1637 library
|
|
|
|
// DATE: 2021-10-12
|
|
|
|
// URL: https://github.com/RobTillaart/TM1637
|
|
|
|
|
|
|
|
|
|
|
|
#include "TM1637.h"
|
|
|
|
|
|
|
|
TM1637 TM;
|
|
|
|
|
2021-12-29 06:48:28 -05:00
|
|
|
|
2021-10-28 04:02:41 -04:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
|
2022-09-25 03:59:53 -04:00
|
|
|
TM.begin(2, 3); // clockpin, datapin
|
|
|
|
|
2021-10-28 04:02:41 -04:00
|
|
|
TM.setBrightness(2);
|
|
|
|
}
|
|
|
|
|
2021-12-29 06:48:28 -05:00
|
|
|
|
2021-10-28 04:02:41 -04:00
|
|
|
void ascii_to_7segment(char *buff, uint8_t *data) {
|
|
|
|
for(int8_t i = 0, j=5 ; j > -1 && i < 12 && buff[i] ; i++) {
|
|
|
|
if(isalpha(buff[i])) { buff[i] = tolower(buff[i]); }
|
|
|
|
if(buff[i] >= '0' && buff[i] <= '9') {
|
|
|
|
data[j--] = buff[i] - '0';
|
|
|
|
}
|
|
|
|
else if(buff[i] >= 'a' && buff[i] <= 'f') {
|
|
|
|
data[j--] = buff[i] - 'a' + 10;
|
|
|
|
}
|
|
|
|
else if(buff[i] >= 'g' && buff[i] <= 'z') {
|
|
|
|
data[j--] = buff[i] - 'g' + 18;
|
|
|
|
}
|
|
|
|
else if(buff[i] == '.') {
|
|
|
|
data[j+1] |= 0x80; // decimal point on previous digit
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data[j--] = 0x10; // blank
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 06:48:28 -05:00
|
|
|
|
2021-10-28 04:02:41 -04:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
char buff[20];
|
|
|
|
uint8_t data[10];
|
|
|
|
strcpy(buff, "hello ");
|
|
|
|
Serial.println("hello");
|
|
|
|
ascii_to_7segment(buff, data);
|
|
|
|
TM.displayRaw(data, -1);
|
|
|
|
delay(1000);
|
|
|
|
TM.displayClear();
|
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
|
2021-12-29 06:48:28 -05:00
|
|
|
|
2021-10-28 04:02:41 -04:00
|
|
|
// -- END OF FILE --
|
2021-12-29 06:48:28 -05:00
|
|
|
|