Chapter 27 Solder Circuit Board 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
    lastMove = time. time()    #the start time 
    w hile Tr ue: 
        if(time.time() - lastMove > moveSpeed): #speed control 
            lastMove = time. time()      #Record the time point of the move 
            index +=1     #move to next  
            if(index > 15):     #index to 0 
                index = 0 
             
        for i in range(0,64):   #The cycle of PWM is 64 cycles 
            data = 0        #This loop of output data 
            for j in range(0,8):    #Calculate the output state of this loop 
                if(i < pluseWidth[j+index]):    #Calculate the LED state according to the 
pulse width  
                    data |= 1<<j    #Calculate the data 
            outData(data)           #Send the data to 74HC595 
 
def destroy():   # When 'Ctrl+C' is pressed, the function is executed.  
    GPIO. cleanup() 
 
if __name__ == '__main__': # Program starting from here  
    p rint ('Program is starting...') 
    setup()  
    try: 
        loop()   
    e xcept KeyboardInterrupt:   
        destroy()  
 
We can see that this procedure is different from the previous running water lamp, we define an array for the 
modulation of different PWM LED pulse width, so that different LED have different brightness. Starting from 
the array index  0, each take  an array of 8  adjacent  numbers, as the LED duty cycle  output, which in turn 
increases the index number, it will produce a flow effect. 
pluseWidth = [ 0, 0,0,0,0,0,0,0,64,32,16,8,4,2,1,0,0,0,0,0,0,0,0] 
 
By recording the moving time point to control the speed of the movement of index number, namely, control 
the flowing speed of flowing water light. Variable moveSpeed saves the time interval of each move, and the 
greater the value, the slower the flowing rate. On the contrary, the faster the flowing. 
        if(time.time() - lastMove > moveSpeed): #speed control 
            lastMove = time. time()      #Record the time point of the move 
            index +=1     #move to next  
            if(index > 15):     #index to 0 
                index = 0