transistor array

ULN2004

transistor array : ULN2004A 8851
http://kitsrus.com/pdf/uln2003a.pdf

------------------------------

Code by Tom Igoe
http://stage.itp.nyu.edu/~tigoe/pcomp/examples/stepper.shtml

' open the file with the definitions that we need:
INCLUDE "modedefs.bas"
' Set Debug pin port
DEFINE DEBUG_REG PORTA
' Set Debug pin BIT (RC4 in this case)
DEFINE DEBUG_BIT 0
' Set Debug baud rate
DEFINE DEBUG_BAUD 9600
james journal:
https://home.nyu.edu/~jvc203/netobj/journal.html


' Set Debug mode: 0 = true, 1 = inverted
DEFINE DEBUG_MODE 1

start:
High PORTB.0


' set variables:
x VAR BYTE
steps VAR WORD
stepArray VAR BYTE(4)
clear

TRISD = %11110000
PORTD = 255
input portb.4
Pause 1000


main:
stepArray[0] = %00001010
stepArray[1] = %00000110
stepArray[2] = %00000101
stepArray[3] = %00001001

if portb.4 = 1 then
steps = steps + 1
else
steps = steps - 1
endif

portD = stepArray[steps //4]
pause 3

GoTo main

----------------------------------------------------------------------------------------------
dim motorStep(1 to 4) as byte
dim thisStep as integer

Sub main()
call delay(0.5) ' start program with a half-second delay

dim i as integer

' save values for the 4 possible states of the stepper motor leads
' in a 4-byte array. the stepMotor routine will step through
' these four states to move the motor. This is a way to set the
' value on four pins at once. The eight pins 5 through 12 are
' represented in memory as a byte called register.portc. We will set
' register.portc to each of the values of the array in order to set
' pins 9,10,11, and 12 at once with each step.

motorStep(0) = bx0000_1010
motorStep(1) = bx0000_0110
motorStep(2) = bx0000_0101
motorStep(3) = bx0000_1001

' set the last 4 pins of port C to output:
register.ddrc = bx0000_1111

' set all the pins of port C low:
register.portc = bx0000_0000

do
' move motor forward 100 steps.
' note: by doing a modulo operation on i (i mod 4),
' we can let i go as high as we want, and thisStep
' will equal 0,1,2,3,0,1,2,3, etc. until the end
' of the for-next loop.

for i = 1 to 100
thisStep = i mod 4
call stepMotor(thisStep)
next

' move motor backward
for i = 100 to 1 step -1
thisStep = i mod 4
call stepMotor(thisStep)
next
loop

End Sub


sub stepMotor(byref whatStep as integer)
' sets the value of the eight pins of port c to whatStep
register.portc = motorStep(whatStep)

call delay (0.1) ' vary this delay as neede to make your stepper step.
end sub


------------------------------------------------------------------