DM13A 16-bit Constant Current LED Driver

Used Products:

1. Arduino UNO
2. DM13A

Code:

#define latchPin 8 #define clkPin 10 #define daiPin 11 int counter = 0; int dir = 1; int del = 100; void setup() { Serial.begin(9600); pinMode(latchPin, OUTPUT); pinMode(clkPin, OUTPUT); pinMode(daiPin, OUTPUT); digitalWrite(latchPin, LOW); digitalWrite(daiPin, LOW); digitalWrite(clkPin, LOW); } void loop() { dir = 1; for (int i = 0; i < 32; i++) { doTrigger(1); delay(del); } dir = 1; for (int i = 0; i < 15; i++) { doTrigger(2); delay(del); } } void doTrigger(int level) { if (dir == 0) { // push 0 doLow(); counter++; } else { doHigh(); counter--; } digitalWrite(latchPin, HIGH); digitalWrite(latchPin, LOW); if (level == 1) { if (counter <= 0) { dir = 0; } else if (counter > 15) { dir = 1; } } else { dir = dir%2==0?1:0; } Serial.print(", dir: "); Serial.print(dir);Serial.print(", counter: "); Serial.print(counter); Serial.println(); } void doLow() { digitalWrite(daiPin, LOW); digitalWrite(clkPin, HIGH); digitalWrite(clkPin, LOW); } void doHigh() { digitalWrite(daiPin, HIGH); digitalWrite(clkPin, HIGH); digitalWrite(clkPin, LOW); digitalWrite(daiPin, LOW); }