Skip to content

Instantly share code, notes, and snippets.

@designer2k2
Last active February 3, 2023 18:49
Show Gist options
  • Save designer2k2/9d62e085ca3b069f6fb57de772c8d489 to your computer and use it in GitHub Desktop.
Save designer2k2/9d62e085ca3b069f6fb57de772c8d489 to your computer and use it in GitHub Desktop.
tm1680 arduino code, leds show, but no idea why...
// TM1680 tryout, A0 must be low, A1 high (floating)
// 01.2023 designer2k2 (Stephan Martin)
// to be run on a 5V capable arduino
#include <Wire.h>
byte ledstatearray[48] = { 0 };
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // start serial for output
Wire.begin(); // join i2c bus
Wire.setClock(400000UL); // we want 400khz?
Serial.println("Start TM1680 init");
// Init the TM1680, same sequence as captured by logic analyczer:
Wire.beginTransmission(0x73); // transmit to device 73
Wire.write(0x80); // SYS DIS
Wire.write(0xA4); // COM option 01
Wire.write(0x9A); // RC Master Mode 1
Wire.write(0x81); // SYS EN
Wire.write(0x83); // LED ON
Wire.write(0xB0); // PWM Duty Min (BF Duty max)
Wire.write(0x88); // Blink Off
Wire.endTransmission(); // stop transmitting
Serial.println("Done with TM1680 init");
delay(50);
blinkall();
}
void blinkall() {
//Blink with 1Hz for 5s
//Turn on all:
for (int i = 0; i < 95; i++) {
Wire.beginTransmission(0x73); // transmit to device 73
Wire.write(i); // Address
Wire.write(0xFF); // full on
Wire.endTransmission(); // stop transmitting
}
delay(100);
Wire.beginTransmission(0x73); // transmit to device 73
Wire.write(0x8A); // Blink 1Hz
Wire.endTransmission(); // stop transmitting
delay(5000);
Wire.beginTransmission(0x73); // transmit to device 73
Wire.write(0x88); // Blink Off
Wire.endTransmission(); // stop transmitting
}
void sendfullarray() {
//Arduino has a 32byte limit, so split the send in 2:
Wire.beginTransmission(0x73); // transmit to device 73
Wire.write(0); // Start on 00
for (unsigned int i = 0; i < 24; i++) {
Wire.write(ledstatearray[i]);
}
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(0x73); // transmit to device 73
Wire.write(48); // Start on 48 (24x2 send above)
for (unsigned int i = 24; i < sizeof ledstatearray / sizeof ledstatearray[0]; i++) {
Wire.write(ledstatearray[i]);
}
Wire.endTransmission(); // stop transmitting
}
void loop() {
// put your main code here, to run repeatedly:
//loop over:
for (unsigned int i = 0; i < sizeof ledstatearray / sizeof ledstatearray[0]; i++) {
byte s = 0x01; //init with 1 bit set
for (uint8_t j = 0; j < 8; j++) {
ledstatearray[i] = s;
Serial.print(i);
Serial.print(" ");
Serial.println(ledstatearray[i], BIN);
sendfullarray();
delay(1);
s = s << 1; //bitshift
}
ledstatearray[i] = 0x00; //reset to 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment