Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #
  2. # Mapa kol z ich numerami z tablic i pinami
  3. #
  4. # Numery:
  5. # ^
  6. # (3) (2)
  7. # (1)__(0)
  8. #
  9. # Piny:
  10. # ^
  11. # (15) (14)
  12. # (18)____(4)
  13.  
  14. from gpiozero import Button
  15. import time
  16. import numpy as np
  17. import smbus
  18. i = []
  19. wyslany_string=""
  20. srednicaKola = 6.5
  21.  
  22. czas_odswiezania = 1
  23. enkoder=[]
  24.  
  25.  
  26. def writeNumber2(value):
  27. bus = smbus.SMBus(1)
  28. address = 0x04
  29. bus.write_byte(address, value)
  30.  
  31. def writeNumber(val):
  32.  
  33. bus = smbus.SMBus(1)
  34. address = 0x04
  35. for character in str(val): # convert into a string and iterate over it
  36. bus.write_byte(address, ord(character)) # send each char's ASCII encoding
  37.  
  38. def liczeniePredkosci(p, k):
  39.  
  40. global srednicaKola
  41. global czas_odswiezania
  42.  
  43. odleglosc = srednicaKola/8*p*3.14
  44. predkosc = odleglosc/czas_odswiezania
  45. predkosc2 = ("{:1.2f}".format(predkosc))
  46. if(predkosc<10):
  47. predkosc2="0"+predkosc2
  48. return predkosc2
  49.  
  50. def licznikPraweTyl():
  51. global i
  52. i[0] = i[0] + 1
  53.  
  54. def licznikLeweTyl():
  55. global i
  56. i[1] = i[1] + 1
  57.  
  58. def licznikPrawePrzod():
  59. global i
  60. i[2] = i[2] + 1
  61.  
  62. def licznikLewePrzod():
  63. global i
  64. i[3] = i[3] + 1
  65.  
  66. for k in range(0,4):
  67. i.append(0)
  68.  
  69.  
  70.  
  71. enkoder.append(Button(4))
  72. enkoder.append(Button(18))
  73. enkoder.append(Button(14))
  74. enkoder.append(Button(15))
  75.  
  76. enkoder[0].when_pressed = licznikPraweTyl
  77. enkoder[1].when_pressed = licznikLeweTyl
  78. enkoder[2].when_pressed = licznikPrawePrzod
  79. enkoder[3].when_pressed = licznikLewePrzod
  80.  
  81.  
  82.  
  83. while(1):
  84. time.sleep(czas_odswiezania)
  85. wysylany_string=""
  86. for k in range(0,4):
  87. p = i[k]
  88. wysylany_string+=str((liczeniePredkosci(p, k)))
  89. i[k]=0
  90. wysylany_string+="0100"
  91. writeNumber(wysylany_string)
  92. print("wysylany string: ", wysylany_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement