ULN2803APG Darlington Driver 8-Channel

used products:

1. Arduino UNO
2. ULN2003APG
3. ULN2803APG

Arduino:

int pins[] = {2,3,4,5,6,7,8,9}; #define commonPin 10 const int ARRAY_SIZE = sizeof(pins) / sizeof(int); int count = 0; void setup() { for (int i = 0; i < ARRAY_SIZE; i++) { pinMode(pins[i], OUTPUT); } pinMode(commonPin, OUTPUT); for (int i = 0; i < ARRAY_SIZE; i++) { digitalWrite(pins[i], LOW); } digitalWrite(commonPin, HIGH); } void loop() { for (int i = 0; i < ARRAY_SIZE; i++) { digitalWrite(pins[i], count==i); } digitalWrite(commonPin, HIGH); count = ++count%8; delay(100); if (count == 0) { digitalWrite(commonPin, LOW); delay(500); } }

C:

#include <avr/io.h> #define F_CPU 16000000 #include <util/delay.h> int pins[] = {2,3,4,5,6,7,8,9}; void digitalWrite(int pin, int state); #define PIN_COMMON PB2 int main(void) { int count = 0; DDRD = 0xfc; DDRB = 0X07; PORTD = 0x00; PORTB = 0x00; PORTB |= (1<<PIN_COMMON); while (1) { for (int i = 0; i < 8; i++) { if (count == i) { digitalWrite(pins[i], 1); } else { digitalWrite(pins[i], 0); } } count++; if (count > 8) { count = 0; PORTB &= ~(1<<PIN_COMMON); _delay_ms(100); } else { _delay_ms(50); } PORTB |= (1<<PIN_COMMON); } } void digitalWrite(int pin, int state) { if (pin >= 2 && pin <= 7) { if (state) { PORTD |= (1<<pin); } else { PORTD &= ~(1<<pin); } } else if (pin >= 8 && pin <= 13) { if (state) { PORTB |= (1<<(pin-8)); } else { PORTB &= ~(1<<(pin-8)); } } }

Great Cow BASIC:

#chip mega328p #define PIN_COMMON PortB.2 Dir PortD 0xFC Dir PortB 0x03 Dir PIN_COMMON Out Dim pins(8) pins = 2, 3, 4, 5, 6, 7, 8, 9 PIN_COMMON = 1 Dim pin as Integer Dim count as Integer count = 0 Do Forever for ii = 1 to 8 pin = pins(ii) If ii-1 = count Then digitalWrite(pin, 1) Else digitalWrite(pin, 0) End If next count = count + 1 If count > 8 Then count = 0 PIN_COMMON = 0 Wait 500 ms Else Wait 100 ms End If PIN_COMMON = 1 Loop sub digitalWrite(portpin as Integer, state as Integer) If portpin = 2 Then PortD.2 = state Else If portpin = 3 Then PortD.3 = state Else If portpin = 4 Then PortD.4 = state Else If portpin = 5 Then PortD.5 = state Else If portpin = 6 Then PortD.6 = state Else If portpin = 7 Then PortD.7 = state Else If portpin = 8 Then PortB.0 = state Else If portpin = 9 Then PortB.1 = state Else If portpin = 10 Then PortB.2 = state Else If portpin = 11 Then PortB.3 = state Else If portpin = 12 Then PortB.4 = state Else If portpin = 13 Then PortB.5 = state End if end sub