Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import smbus
  2.  
  3. bus = smbus.SMBus(1)
  4.  
  5. v = bus.read_byte_data(0x57, 0xff)
  6. if v != 17:
  7. print "wrong part ID"
  8. exit(1)
  9.  
  10. bus.write_byte_data(0x57, 0x06, 0x03)
  11.  
  12. p = bus.read_byte_data(0x57, 0x07)
  13. bus.write_byte_data(0x57, 0x07, (p & 0xfc) | 0x03)
  14.  
  15. p = bus.read_byte_data(0x57, 0x07)
  16. bus.write_byte_data(0x57, 0x07, (p & 0xe3) | (0x01 << 2))
  17.  
  18. bus.write_byte_data(0x57, 0x09, 0x0f << 4 | 0x0f)
  19.  
  20. p = bus.read_byte_data(0x57, 0x07)
  21. bus.write_byte_data(0x57, 0x07, p | (1 << 6))
  22.  
  23. alpha = 0.95
  24. dcw = 0.0
  25. lpf = [ 0.0, 0.0 ]
  26. while True:
  27. buffer = bus.read_i2c_block_data(0x57, 0x05, 4)
  28. rawIRValue = (buffer[0] << 8) | buffer[1]
  29. rawRedValue = (buffer[2] << 8) | buffer[3]
  30.  
  31. olddcw = dcw
  32. dcw = rawIRValue + alpha * dcw
  33. irACValue = dcw - olddcw
  34.  
  35. lpf[0] = lpf[1]
  36. lpf[1] = (2.452372752527856026e-1 * (-irACValue)) + (0.50952544949442879485 * lpf[0])
  37.  
  38. print (lpf[0] + lpf[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement