# Package to use standard math functions and values. import math import winsound import time # Package to handle array operations. import numpy as np # Pckage to load .mat files. from scipy.io import loadmat # Register class defined in the same folder to interact with microcontroller # to input the bits in serial manner. from PCB_Register_Class import shiftRegister ############################################################################### correct_order = np.array([ [5,4,3,2,1,81,82,83,84,85], [10,9,8,7,6,86,87,88,89,90], [15,14,13,12,11,91,92,93,94,95], [20,19,18,17,16,96,97,98,99,100], [25,24,23,22,21,101,102,103,104,105], [30,29,28,27,26,106,107,108,109,110], [35,34,33,32,31,111,112,113,114,115], [40,39,38,37,36,116,117,118,119,120], [45,44,43,42,41,121,122,123,124,125], [50,49,48,47,46,126,127,128,129,130], [55,54,53,52,51,131,132,133,134,135], [60,59,58,57,56,136,137,138,139,140], [65,64,63,62,61,141,142,143,144,145], [70,69,68,67,66,146,147,148,149,150], [75,74,73,72,71,151,152,153,154,155], [80,79,78,77,76,156,157,158,159,160] ]) print(correct_order) ############################################################################### # Instantiate a shift register object # Data pin is GPIO 11, serial clock pin is GPIO 12, Latch pin is GPIO 8 # shiftRegister = shiftRegister(2,8) shiftRegister = shiftRegister(23,25,27,29,31,33,35,37,39,41,49,47) # Loading the quantized phase matrix .mat file. matrix = loadmat("10m_0_0_60.mat") # Extracting the required array from the loaded .mat file. data = matrix['phi_ph_shift_q'] #frequency = 2500 # Set Frequency To 2500 Hertz #duration = 1000 # Set Duration To 1000 ms == 1 second #winsound.Beep(frequency, duration) #time.sleep(10) for index in range(1): print("------------------------------------------------------------------") print('Reflection Angle = '+str((index)*2.5)) print(" ") print('Phase Pattern for Reflection Angle '+str((index)*2.5)+'degree:') # Normalising the data array and converting the elem from float to int. norm_ph = (data[:,:,index]//math.pi).astype(int) print(norm_ph) print(' ') # Storing the left half of the 16x10 data array. left_half = norm_ph[:,0:5] #print(left_half) # Flips the vector from left to right and then converts the matrix to # vec and to arrange the bits in desired manner for the lower 80 leds. lower_led_bits = np.fliplr(left_half).flatten() #print(lower_led_bits) # Storing the right half of the 16x10 data array. right_half = norm_ph[:,5:10] #print(right_half) # Converts the matrix to vector. upper_led_bits = right_half.flatten() #print(upper_led_bits) # Order of all 160 leds bits in the desired manner. all_led_bits = np.append(lower_led_bits,upper_led_bits) print("Vector being input to the Microcontroller:") # all_led_bits = np.ones(160) all_led_bits = (0,0,1,1,1,1,1,0, 1,1,1,1,1,1,1,1, 0,0,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 0,0,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,0,0,0) print(all_led_bits) print(' ') # Calls the method outputBits in the shiftRegister class. shiftRegister.outputBits(all_led_bits) # frequency = 2500 # Set Frequency To 2500 Hertz # duration = 2000 # Set Duration To 1000 ms == 1 second # winsound.Beep(frequency, duration) # # time.sleep(2)