Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
def strengthdisplay (data): """turn 8 bit data into a number between 0 and 6""" data = int(data / 37) led = 0 if data == 0: led = 0b000000 elif data == 1: led = 0b000001 elif data == 2: led = 0b000011 elif data == 3: led = 0b000111 elif data == 4: led = 0b001111 elif data == 5: led = 0b011111 else: led = 0b111111 return leddef doublestrengthdisplay (data1, data2): """turn two lots of 8 bit data into 2 numbers between 0 and 3""" data1 = int(data1/64) data2 = int(data2/64) led = 0 #process the first signal if data1 == 0: led = 0b000000 elif data1 == 1: led = 0b000001 elif data1 == 2: led = 0b000011 else: led = 0b000111 #now append the second signal if data2 == 0: led += 0b000000 elif data2 ==1: led += 0b100000 elif data2 ==2: led += 0b110000 else: led += 0b111000 return leddef sigdifference (data1, data2): """compares data1 to data2 and plots the difference""" #subtracting an 8 bit number from another 8 bit number can have a #difference of 511, we need to create a number between -3 and 3 number = (int(data1 / 64) - int(data2 / 64)) led = 0 if number ==-3: led = 0b000001 elif number ==-2: led = 0b000010 elif number ==-1: led = 0b000100 elif number == 0: led = 0b000000 elif number == 1: led = 0b001000 elif number == 2: led = 0b010000 elif number == 3: led = 0b100000 return leddef display (ledout): """switch on the lights""" #create a binary listing of ledout ledout = bin(ledout) # something to remove the "0b" prefix should go here, this may just be python #also it should make sure that all the '0's are there #ledno = 0 #used to chose which led should be switched on for x in (bin(5)): if x > "0": print ("x") #portoff(ledno) elif x < "1": print ("O")#proton(ledno) #ledno += 1#a bit of code here to give an example of the functionsimport randomprint ("strengthdisplay:")for x in range(20): print (bin((strengthdisplay(random.randint(0, 255)))))print ("doublestrengthdisplay:")for x in range(20): print (bin(doublestrengthdisplay(random.randint(0,255),random.randint(0,255))))print ("sigdifference:")for x in range(20): print (bin(sigdifference(random.randint(0,255),random.randint(0,255))))
DDRD = 0xFF;
PORTD = 0b00001111;