Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : SPI and the Maximite
Page 2 of 2 | |||||
Author | Message | ||||
Shaz_Au Newbie Joined: 31/10/2012 Location: AustraliaPosts: 11 |
I haven't yet got the hardware to test it but I'm hoping this code won't be too far off... Any corrections or tips would be great! 'Maximite 74HC595 Shift Register Test 'Adapted from the Arduino ShiftOut Tutorial - Hello World Code 'Original Code available from http://arduino.cc/en/Tutorial/ShftOut11 'Pin connected to ST_CP of 74HC595 latchPin = 13 'Pin connected to SH_CP of 74HC595 clockPin = 12 'Pin connected to DS of 74HC595 dataPin = 11 'Setup pins to digital output SETPIN latchPin, 8 SETPIN clockPin, 8 SETPIN dataPin, 8 'create an unused RX pin for SPI function rxPin = 14 'set rxPin as a digital input SETPIN rxPin, 2 ' count from 0 to 255 and display the number on the LEDs for numberToDisplay = 0 TO 255 'take the latchPin low so the LEDs don't change while you're sending in bits PIN(latchPin)=0 'shift out the bits junk = SPI(rxPin, dataPin, clockPin, numberToDisplay) 'take the latch pin high so the LEDs will light up PIN(latchPin)=1 'pause before next value PAUSE 500 NEXT numbertoDisplay |
||||
MM_Wombat Senior Member Joined: 12/12/2011 Location: AustraliaPosts: 139 |
@ Shaz_AU Essentially, you have it correct, but the command for SPI changed @ V3 I think, and the new format is received_data = SPI( rx, tx, clk, data_to_send, speed, mode, bits ) bits default to 8 and can be omitted for a single 595 chip. Two chips daisy chained together and you could set bits as 16 (send two bytes) to send both chips the desired output. Bits maximum is 24 I think. My command for SPI_DMD() has this bits set to 32. I also found the mode may need to be changed to 3 for the 595 chip.. Just try the default of zero. If no output try setting the mode to 3. ie: junk = SPI(rxPin, dataPin, clockPin, numberToDisplay, H, 0) or junk = SPI(rxPin, dataPin, clockPin, numberToDisplay, H, 3) An extract from Tronixstuff Arduino Tutorial Chapter 4 1) set the latch pin low (pin 12)
2) send the byte of data to the ’595 (pin 14) 3) toggle the clock pin (pin 11) 4) set the latch pin high (pin 12) Pin 10 (reset) is always connected to the +5V, pin 13 (output enable) is always connected to ground. Thankfully there is a command that has parts 2 and 3 in one; you can use digitalWrite(); to take care of the latch duties. The command shiftOut(); is the key. The syntax is: shiftout(a,b,c,d); where: a = the digital output pin that connects to the ’595 data pin (14); b = the digital output pin that connects to the ’595 clock pin (11); c can be either LSBFIRST or MSBFIRST. MSBFIRST means the ’595 will interpret the binary number from left to right; LSBFIRST will make it go right to left; d = the actual number (0~255) that you want represented by the ’595 in binary output pins. for an example I supply my code from version 3. It opens a file for output and stores the junk variable in a spreadsheet file. The junk gets this returned from pin 9 (rx)of the 595 chip ( connect pin 9 to pin 14 to daisy chain two 595 together..) SetPin 18, 2 'set rx pin AS a digital input
SetPin 19, 8 'set tx pin AS an output Pin(20) = 1 : SetPin 20, 8 ' set clk pin high THEN set it AS an output Pin(17) = 1 : SetPin 17, 8 'pin 17 will be used AS the enable signal Cls Option base 0 Open "SPI-DATA.xls" For output As #1 Do While temp <255 temp=(temp+1) Mod 255 Pause 50 GoSub senddata Loop Close #1 End SendData: ' send spi data routine Pin(17) = 0 'assert the enable line (active low) Pause 1 junk = SPI(18 , 19 , 20 , temp , H , 0) 'send the command Pause 1 Pin(17) = 1 'deselect the slave Locate 100,100: ? " " Locate 100,100 : ? temp;",";junk Print #1 " ";temp;",";junk Return Regards Dennis Keep plugging away, it is fun learning But can be expensive (if you keep blowing things up). Maximite, ColourMaximite, MM+ |
||||
Shaz_Au Newbie Joined: 31/10/2012 Location: AustraliaPosts: 11 |
Hi Dennis, Thank you for the comprehensive reply, it has helped a lot! I think I understand it now anyway... - So is there a reason why you set the clock and latch pins high at the start of the program? Would this not display whatever junk is in the shift register at startup? - Is the pauses you have in the sendData function necessary? - Expanding on your idea of 2 registers daisy chained together; if I wanted to send data to 4 registers is it just a matter of pulling the latch pin low, dividing up the 32bits into two 16bit spi commands and sending them one after another, then pulling the latch pin high again? I don't actually want to do this, I'm just curious. My first goal is to use two 74hc595 chips to build a 8x8 switch matrix that along with 8 NPN(TP102), 8 PNP(TP107) transistors and a lot of diodes can control 64 separate lamp outputs. Now if only the postie would hurry up and do his part so I can get started Thanks, Shannon |
||||
MM_Wombat Senior Member Joined: 12/12/2011 Location: AustraliaPosts: 139 |
@ Shaz_AU Yes you would do just that. When I had four 595's connected together, and The command was 8 bits, I would send 4 8 bit commands. temp1=234 temp2=56 temp3=45 temp4=176 Pin(17) = 0 'assert the enable line (active low) junk = SPI(18 , 19 , 20 , temp1 , H) 'send the command junk = SPI(18 , 19 , 20 , temp2 , H) 'send the command junk = SPI(18 , 19 , 20 , temp3 , H) 'send the command junk = SPI(18 , 19 , 20 , temp4 , H) 'send the command Pin(17) = 1 'deselect the slave but now would be temp1=234 temp2=56 temp3=45 temp4=176 Pin(17) = 0 'assert the enable line (active low) junk = SPI(18 , 19 , 20 , (temp2*256)+temp1 , H, 0, 16) 'send the command junk = SPI(18 , 19 , 20 , (temp4*256)+temp3 , H, 0, 16) 'send the command Pin(17) = 1 'deselect the slave I suppose I set the pins high, so as there would be a transition from high to low. I don't know if it would make any difference, as it would only be a approx 35 nano seconds per line before my data was sent.... Regards Dennis PS. With the DMD panels, you only have to tell the program how many horizontal and vertical panels you have, and then draw everything to the screen, and it will display on the panels automatically. Maybe I should add it to the library, with a .hex of the Maximite version which holds the SPI_DMD() command added to the source.. Am still working on getting it to work on the CMM though.... Keep plugging away, it is fun learning But can be expensive (if you keep blowing things up). Maximite, ColourMaximite, MM+ |
||||
MM_Wombat Senior Member Joined: 12/12/2011 Location: AustraliaPosts: 139 |
@ Shaz_AU I also experimented with an 'Austria Micro Systems' AS1107 8x8 controllers This is the thread link It may be easier than using the 595's There is also a Maxim chip, 7219, but I think it was discontinued? Regards Dennis PS. The code for the 3x 8x8...from the link... mytext$=" Maximite by Geoff Graham, MMBasic V3.2 . Program by Dennis Wyatt."
SetPin 18, 2 'set rx pin AS a digital input SetPin 19, 8 'set tx pin AS an output Pin(20) = 1 : SetPin 20, 8 ' set clk pin high THEN set it AS an output Pin(17) = 1 : SetPin 17, 8 'pin 17 will be used AS the enable signal Cls hex1 = 0 : test1 = 0 Option base 0 Dim blink(3) : blink(0)=160 : blink(1)=176 : blink(2)=144 blinker=0 pausetime=51 Dim bcodeHEX(2) : bcodeHEX(0)=0 : bcodehex(1)=4 Dim displaydigit0(1500) ' 250 Characters 6 column wide Dim characters(96,5) GoSub dataread GoSub builddisplaydata leadingzeroes$="000000000000" 'setup chips temp1=&H0900 ' no decode mode temp2=temp1 temp3=temp1 GoSub senddata temp1=&H0b07 ' scan limit temp2=temp1 temp3=temp1 GoSub senddata temp1=&H0A04 'intensity global temp2=temp1 temp3=temp1 GoSub senddata temp1=&H0C81 ' wake up temp2=temp1 temp3=temp1 GoSub senddata Do text$=Inkey$ If text$="3" Then 'test display test1=Not test1 temp1=&H0F00 + test1 temp2=temp1 temp3=temp1 GoSub senddata EndIf If text$="8" Or text$="q" Then 'shutdown temp1=&H0C80 temp2=temp1 temp3=temp1 GoSub senddata If text$="q" Then End EndIf If text$="b" Then 'blink blinker=(blinker + 1) Mod 3 GoSub buildfeature temp2=temp1 temp3=temp1 GoSub senddata EndIf 'write all digits then increment textpos to scroll text temp1=&H0100+displaydigit0(textpos Mod scrollcount) temp2=&H0100+displaydigit0((textpos+8) Mod scrollcount) temp3=&H0100+displaydigit0((textpos+16) Mod scrollcount) GoSub senddata temp1=&H0200+displaydigit0((textpos+1) Mod scrollcount) temp2=&H0200+displaydigit0((textpos+9) Mod scrollcount) temp3=&H0200+displaydigit0((textpos+17) Mod scrollcount) GoSub senddata temp1=&H0300+displaydigit0((textpos+2) Mod scrollcount) temp2=&H0300+displaydigit0((textpos+10) Mod scrollcount) temp3=&H0300+displaydigit0((textpos+18) Mod scrollcount) GoSub senddata temp1=&H0400+displaydigit0((textpos+3) Mod scrollcount) temp2=&H0400+displaydigit0((textpos+11) Mod scrollcount) temp3=&H0400+displaydigit0((textpos+19) Mod scrollcount) GoSub senddata temp1=&H0500+displaydigit0((textpos+4) Mod scrollcount) temp2=&H0500+displaydigit0((textpos+12) Mod scrollcount) temp3=&H0500+displaydigit0((textpos+20) Mod scrollcount) GoSub senddata temp1=&H0600+displaydigit0((textpos+5) Mod scrollcount) temp2=&H0600+displaydigit0((textpos+13) Mod scrollcount) temp3=&H0600+displaydigit0((textpos+21) Mod scrollcount) GoSub senddata temp1=&H0700+displaydigit0((textpos+6) Mod scrollcount) temp2=&H0700+displaydigit0((textpos+14) Mod scrollcount) temp3=&H0700+displaydigit0((textpos+22) Mod scrollcount) GoSub senddata temp1=&H0800+displaydigit0((textpos+7) Mod scrollcount) temp2=&H0800+displaydigit0((textpos+15) Mod scrollcount) temp3=&H0800+displaydigit0((textpos+23) Mod scrollcount) GoSub senddata textpos=textpos+1 Pause pausetime If text$="i" Then Print "Please enclose in quotes, for punctuation to be displayed" Input "Enter text "; mytext$ Print Len(mytext$) GoSub builddisplaydata EndIf If text$="p" Then pausetime = (pausetime +10) Mod 200 Print pausetime EndIf Loop senddata: ' rem Pin(17) = 0 'assert the enable line (active low) Timer = 0 junk1 = SPI(18, 19, 20, temp3, H, 0, 16) 'send the command junk1 = SPI(18, 19, 20, temp2, H, 0, 16) 'send the command junk1 = SPI(18, 19, 20, temp1, H, 0, 16) 'send the command tempcount=(tempcount+1) Mod 256 junk2 = SPI(18,19,20,tempcount,H,0,8) Pin(17) = 1 'deselect the slave Return buildFeature: temp1=&H0E00 temp1= temp1 Or bcodehex(hex1) temp1= temp1 Or blink(blinker) Return Dataread: For i= 0 To 95 For j= 0 To 4 Read a characters(i,j)= a Next j Next i Return Data &b00000000, &b00000000, &b00000000, &b00000000, &b00000000 ' space Data &b00000000, &b00000000, &b01111001, &b00000000, &b00000000 ' exclamation_mark Data &b00000000, &b01110000, &b00000000, &b01110000, &b00000000 ' double_quotes Data &b00010100, &b01111111, &b00010100, &b01111111, &b00010100 ' hash Data &b00010010, &b00101010, &b01111111, &b00101010, &b00100100 ' dollar_sign Data &b01100010, &b01100100, &b00001000, &b00010011, &b00100011 ' percent Data &b00110110, &b01001001, &b01010101, &b00100010, &b00000101 ' ampersand Data &b00000000, &b01010000, &b01100000, &b00000000, &b00000000 ' apostrophe Data &b00000000, &b00011100, &b00100010, &b01000001, &b00000000 ' left_parenthesis Data &b00000000, &b01000001, &b00100010, &b00011100, &b00000000 ' right_parenthesis Data &b00010100, &b00001000, &b00111110, &b00001000, &b00010100 ' asteriska Data &b00001000, &b00001000, &b00111110, &b00001000, &b00001000 ' plus Data &b00000000, &b00000101, &b00000110, &b00000000, &b00000000 ' comma Data &b00001000, &b00001000, &b00001000, &b00001000, &b00001000 ' minus Data &b00000000, &b00000011, &b00000011, &b00000000, &b00000000 ' full_stop Data &b00000010, &b00000100, &b00001000, &b00010000, &b00100000 ' forward_slash Data &b00111110, &b01000101, &b01001001, &b01010001, &b00111110 ' zero Data &b00000000, &b00100001, &b01111111, &b00000001, &b00000000 ' one Data &b00100001, &b01000011, &b01000101, &b01001001, &b00110001 ' two Data &b01000010, &b01000001, &b01010001, &b01101001, &b01000110 ' three Data &b00001100, &b00010100, &b00100100, &b01111111, &b00000100 ' four Data &b01110010, &b01010001, &b01010001, &b01010001, &b01001110 ' five Data &b00011110, &b00101001, &b01001001, &b01001001, &b00000110 ' six Data &b01000000, &b01000111, &b01001000, &b01010000, &b01100000 ' seven Data &b00110110, &b01001001, &b01001001, &b01001001, &b00110110 ' eight Data &b00110000, &b01001001, &b01001001, &b01001010, &b00111100 ' nine Data &b00000000, &b00110110, &b00110110, &b00000000, &b00000000 ' colon Data &b00000000, &b00110101, &b00110110, &b00000000, &b00000000 ' semicolon Data &b00001000, &b00010100, &b00100010, &b01000001, &b00000000 ' less_than Data &b00010100, &b00010100, &b00010100, &b00010100, &b00010100 ' equals Data &b00000000, &b01000001, &b00100010, &b00010100, &b00001000 ' greater_than Data &b00100000, &b01000000, &b01000101, &b01001000, &b00110000 ' question_mark Data &b00100110, &b01001001, &b01001111, &b01000001, &b00111110 ' at Data &b00111111, &b01000100, &b01000100, &b01000100, &b00111111 ' A Data &b01111111, &b01001001, &b01001001, &b01001001, &b00110110 ' B Data &b00111110, &b01000001, &b01000001, &b01000001, &b00100010 ' C Data &b01111111, &b01000001, &b01000001, &b00100010, &b00011100 ' D Data &b01111111, &b01001001, &b01001001, &b01001001, &b01000001 ' E Data &b01111111, &b01001000, &b01001000, &b01001000, &b01000000 ' F Data &b00111110, &b01000001, &b01001001, &b01001001, &b00101111 ' G Data &b01111111, &b00001000, &b00001000, &b00001000, &b01111111 ' H Data &b00000000, &b01000001, &b01111111, &b01000001, &b00000000 ' I Data &b00000010, &b00000001, &b01000001, &b01111110, &b01000000 ' J Data &b01111111, &b00001000, &b00010100, &b00100010, &b01000001 ' K Data &b01111111, &b00000001, &b00000001, &b00000001, &b00000001 ' L Data &b01111111, &b00100000, &b00011000, &b00100000, &b01111111 ' M Data &b01111111, &b00010000, &b00001000, &b00000100, &b01111111 ' N Data &b00111110, &b01000001, &b01000001, &b01000001, &b00111110 ' O Data &b01111111, &b01001000, &b01001000, &b01001000, &b00110000 ' P Data &b00111110, &b01000001, &b01000101, &b01000010, &b00111101 ' Q Data &b01111111, &b01001000, &b01001100, &b01001010, &b00110001 ' R Data &b00110001, &b01001001, &b01001001, &b01001001, &b01000110 ' S Data &b01000000, &b01000000, &b01111111, &b01000000, &b01000000 ' T Data &b01111110, &b00000001, &b00000001, &b00000001, &b01111110 ' U Data &b01111100, &b00000010, &b00000001, &b00000010, &b01111100 ' V Data &b01111110, &b00000001, &b00001110, &b00000001, &b01111110 ' W Data &b01100011, &b00010100, &b00001000, &b00010100, &b01100011 ' X Data &b01110000, &b00001000, &b00000111, &b00001000, &b01110000 ' Y Data &b01000011, &b01000101, &b01001001, &b01010001, &b01100001 ' Z Data &b00000000, &b01111111, &b01000001, &b01000001, &b00000000 ' left_square Data &b00100000, &b00010000, &b00001000, &b00000100, &b00000010 ' back_slash Data &b00000000, &b01000001, &b01000001, &b01111111, &b00000000 ' right_square Data &b00010000, &b00100000, &b01000000, &b00100000, &b00010000 ' circumflex Data &b10000000, &b10000000, &b10000000, &b10000000, &b10000000 ' underscore Data &b00000000, &b01000000, &b00100000, &b00010000, &b00000000 ' grave_accent Data &b00000010, &b00010101, &b00010101, &b00010101, &b00001111 ' a Data &b01111111, &b00001001, &b00001001, &b00001001, &b00000110 ' b Data &b00001110, &b00010001, &b00010001, &b00010001, &b00010001 ' c Data &b00000110, &b00001001, &b00001001, &b00001001, &b01111111 ' d Data &b00001110, &b00010101, &b00010101, &b00010101, &b00001101 ' e Data &b00000000, &b00001000, &b00111111, &b01001000, &b00100000 ' f Data &b00001001, &b00010101, &b00010101, &b00010101, &b00011110 ' g Data &b01111111, &b00001000, &b00001000, &b00001000, &b00000111 ' h Data &b00000000, &b00000000, &b00101111, &b00000000, &b00000000 ' i Data &b00000010, &b00000001, &b00000001, &b01011110, &b00000000 ' j Data &b00000000, &b01111111, &b00000100, &b00001010, &b00010001 ' k Data &b00000000, &b01000001, &b01111111, &b00000001, &b00000000 ' l Data &b00011111, &b00010000, &b00001110, &b00010000, &b00011111 ' m Data &b00011111, &b00001000, &b00010000, &b00010000, &b00001111 ' n Data &b00001110, &b00010001, &b00010001, &b00010001, &b00001110 ' o Data &b00011111, &b00010100, &b00010100, &b00010100, &b00001000 ' p Data &b00001000, &b00010100, &b00010100, &b00010100, &b00011111 ' q Data &b00011111, &b00001000, &b00010000, &b00010000, &b00001000 ' r Data &b00001001, &b00010101, &b00010101, &b00010101, &b00010010 ' s Data &b00010000, &b00010000, &b01111110, &b00010001, &b00010010 ' t Data &b00011110, &b00000001, &b00000001, &b00000001, &b00011110 ' u Data &b00011100, &b00000010, &b00000001, &b00000010, &b00011100 ' v Data &b00011110, &b00000001, &b00000110, &b00000001, &b00011110 ' w Data &b00010001, &b00001010, &b00000100, &b00001010, &b00010001 ' x Data &b00010000, &b00001001, &b00000110, &b00001000, &b00010000 ' y Data &b00010001, &b00010011, &b00010101, &b00011001, &b00010001 ' z Data &b00001000, &b00110110, &b01000001, &b01000001, &b00000000 ' leftcurly Data &b00000000, &b00000000, &b01111111, &b00000000, &b00000000 ' vertline Data &b00000000, &b01000001, &b01000001, &b00110110, &b00001000 ' rightcurly Data &b00000100, &b00001000, &b00001000, &b00001000, &b00010000 ' tilde Data &b01111111, &b01000001, &b01000001, &b01000001, &b01111111 ' del buildDisplayData: scrollcount=0 textpos=0 For k=1 To Len(mytext$) chartext=Asc(Mid$(mytext$,k,1)) chartext=chartext-32 displaydigit0((k-1)*6)=characters(chartext,0) displaydigit0((k-1)*6+1)=characters(chartext,1) displaydigit0((k-1)*6+2)=characters(chartext,2) displaydigit0((k-1)*6+3)=characters(chartext,3) displaydigit0((k-1)*6+4)=characters(chartext,4) If chartext=63 Then displaydigit0((k-1)*6+5)=&b10000000 Else displaydigit0((k-1)*6+5)=0 EndIf scrollcount=scrollcount+6 Next k displaydigit0(scrollcount+0)=0 displaydigit0(scrollcount+1)=0 displaydigit0(scrollcount+2)=0 displaydigit0(scrollcount+3)=0 displaydigit0(scrollcount+4)=0 displaydigit0(scrollcount+5)=0 scrollcount=scrollcount+6 Return Keep plugging away, it is fun learning But can be expensive (if you keep blowing things up). Maximite, ColourMaximite, MM+ |
||||
Shaz_Au Newbie Joined: 31/10/2012 Location: AustraliaPosts: 11 |
Wow that code just went flying right over my head :) You are way in front of me, I haven't done any programming in years! I only just put my mono maximite together last month. It's been sitting in a cupboard patiently waiting for me for a long time. Thanks for the further tips, I'll have a look into the AMS 8x8 controllers too. The 595s are good because there is lots of example code and tutorials available for novices like me. I did look at the maxim chips but I think they were like $20 each so that put me off. |
||||
MM_Wombat Senior Member Joined: 12/12/2011 Location: AustraliaPosts: 139 |
Thats ok Any questions just ask.. Dennis Keep plugging away, it is fun learning But can be expensive (if you keep blowing things up). Maximite, ColourMaximite, MM+ |
||||
Shaz_Au Newbie Joined: 31/10/2012 Location: AustraliaPosts: 11 |
So the postie delivered some goodies and I got straight into it. Guess what... It actually worked first time! That never happens. Can you tell I haven't used breadboard before? Now to add a 2nd shift register and modify my basic code to use those leds too before I play with any matrixing Thanks for the help Dennis Cheers, Shaz |
||||
Shaz_Au Newbie Joined: 31/10/2012 Location: AustraliaPosts: 11 |
V2.0 2 shift registers 16 LEDs 3 light effects (knight rider + additive scroll from left & right) Here is the breadboard: Here is the code (some of the repetitive comments could of been removed!): 'Maximite 74HC595 Multiple Shift Register Test
'Knight Rider style display with 16 leds 'Code by Shaz_Au, with thanks to MM_Wombat, the Maximite Library contributors and the Arduino Shift Out Tutorials 'Last updated 12/5/13 'Pin connected to ST_CP of 74HC595 latchPin = 13 'Pin connected to SH_CP of 74HC595 clockPin = 12 'Pin connected to DS of 74HC595 dataPin = 11 'Setup pins to digital output SETPIN latchPin, 8 SETPIN clockPin, 8 SETPIN dataPin, 8 'create an unused RX pin for SPI function rxPin = 14 'set rxPin as a digital input SETPIN rxPin, 2 repeat = 5 'Number of times to repeat each light sequence dim knight(17) 'Create array to store light sequence GoSub dataRead 'Read light sequence into the knight array GoSub knightRider 'Run the knightrider light sequence GoSub scrollFillLeft 'Run fill from left light sequence GoSub scrollFillRight 'Run fill from right light sequence GoSub turnOffTheLights END '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' dataRead: 'input data into array For i=0 To 16 READ knight(i) Next i Return Data &b0000000000000000 'all lights off Data &b1000000000000000 Data &b0100000000000000 Data &b0010000000000000 Data &b0001000000000000 Data &b0000100000000000 Data &b0000010000000000 Data &b0000001000000000 Data &b0000000100000000 Data &b0000000010000000 Data &b0000000001000000 Data &b0000000000100000 Data &b0000000000010000 Data &b0000000000001000 Data &b0000000000000100 Data &b0000000000000010 Data &b0000000000000001 '' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' knightRider: For i=0 to repeat For leftToRight = 1 To 15 'take the latchPin low so the LEDs don't change while you're sending in bits PIN(latchPin)=0 'shift out the bits junk = SPI(rxPin, dataPin, clockPin, knight(leftToRight), H, 3, 16) 'where junk is a dummy variable, 'H is the speed (high - default) '3 is the mode (Clock is active low, data is captured on the rising edge and output on the falling edge - default) '16 is the number of bits to transfer 'take the latch pin high so the LEDs will light up PIN(latchPin)=1 'pause before next value PAUSE 60 NEXT leftToRight If i = repeat then 'if this is the last cycle then cycle all the way down to 0 lights lastCycle=0 Else 'light sequence is going to repeat so cycle down to 2nd to last light ready for next leftToRight loop lastCycle=2 EndIf For rightToLeft = 16 To lastcycle STEP -1 'take the latchPin low so the LEDs don't change while you're sending in bits PIN(latchPin)=0 'shift out the bits junk = SPI(rxPin, dataPin, clockPin, knight(rightToLeft), H, 3, 16) 'where junk is a dummy variable, 'H is the speed (high - default) '3 is the mode (Clock is active low, data is captured on the rising edge and output on the falling edge - default) '16 is the number of bits to transfer 'take the latch pin high so the LEDs will light up PIN(latchPin)=1 'pause before next value PAUSE 60 NEXT rightToLeft NEXT i RETURN ''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' scrollFillLeft: For i=0 to repeat total=0 For remainLit = 1 to 16 For j=16 to remainLit STEP -1 PIN(latchPin)=0 'take the latchPin low so the LEDs don't change while you're sending in bits junk = SPI(rxPin, dataPin, clockPin, total+knight(j), H, 3, 16) 'shift out the bits 'where junk is a dummy variable, 'H is the speed (high - default) '3 is the mode (Clock is active low, data is captured on the rising edge and output on the falling edge - default) '16 is the number of bits to transfer PIN(latchPin)=1 'take the latch pin high so the LEDs will light up PAUSE 60 'pause before next value Next j total=total+knight(remainLit) Next remainLit Next i Return '''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' scrollFillRight: For i=0 to repeat total=0 For remainLit = 0 to 16 For j=0 to 16-remainLit PIN(latchPin)=0 'take the latchPin low so the LEDs don't change while you're sending in bits junk = SPI(rxPin, dataPin, clockPin, total+knight(j), H, 3, 16) 'shift out the bits 'where junk is a dummy variable, 'H is the speed (high - default) '3 is the mode (Clock is active low, data is captured on the rising edge and output on the falling edge - default) '16 is the number of bits to transfer PIN(latchPin)=1 'take the latch pin high so the LEDs will light up PAUSE 60 'pause before next value Next j total=total+knight(16-remainLit) Next remainLit Next i Return '''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' turnOffTheLights: 'take the latchPin low so the LEDs don't change while you're sending in bits PIN(latchPin)=0 'shift out the bits junk = SPI(rxPin, dataPin, clockPin, knight(0), H, 3, 16) 'where junk is a dummy variable, 'H is the speed (high - default) '3 is the mode (Clock is active low, data is captured on the rising edge and output on the falling edge - default) '16 is the number of bits to transfer 'take the latch pin high so the LEDs will light up PIN(latchPin)=1 Return If you have any other ideas for cool lighting effects I should try then please let me know. Thanks for looking! |
||||
Page 2 of 2 |
Print this page |