Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. def Start(self):
  2. import time
  3. import os
  4. import RPi.GPIO as GPIO
  5. import datetime
  6.  
  7. GPIO.setmode(GPIO.BCM)
  8. DEBUG = 1
  9.  
  10. os.system('clear')
  11.  
  12. # SPI port on GPIO
  13. SPICLK = 18
  14. SPIMISO = 23
  15. SPICS = 25
  16.  
  17. # set up the SPI interface pins
  18. GPIO.setup(SPIMISO, GPIO.IN)
  19. GPIO.setup(SPICLK, GPIO.OUT)
  20. GPIO.setup(SPICS, GPIO.OUT)
  21.  
  22. GPIO.output(SPICS, True)
  23. GPIO.output(SPICS, False) # bring CS low
  24. while True:
  25. adcout = 0
  26. read_adc = 0
  27. #s=time.clock()
  28. for i in range(25):
  29. GPIO.output(SPICLK, True)
  30. GPIO.output(SPICLK, False)
  31. adcout <<= 1
  32. if (GPIO.input(SPIMISO)==1):
  33. adcout |= 0x1
  34. time.sleep(0.085)
  35. if (GPIO.input(SPIMISO)==0):
  36. read_adc = adcout
  37. millivolts = read_adc * ( 2500.0 /(pow(2,22)))
  38. read_adc = "%d" % read_adc
  39. millivolts = "%d" % millivolts
  40.  
  41. if DEBUG:
  42. print millivolts, "mV (ADC)"
  43.  
  44. from guiLoop import guiLoop, stopLoop
  45. # ... means fill in your code
  46. class ...:
  47. started = False
  48.  
  49. def Start(self):
  50. if not self.started:
  51. # you can also use threads here, see the first link
  52. self.started = self.StartLoop()
  53.  
  54. def Stop(self):
  55. if self.started:
  56. stopLoop(self.started)
  57. self.started = False
  58.  
  59. @guiLoop
  60. def StartLoop(self):
  61. # This is your Start function
  62. # ...
  63. while True:
  64. # ...
  65. yield 0.085 # time.sleep(0.085) equivalent
  66. # ...
  67.  
  68. from PyQt4 import QtGui
  69. import sys
  70.  
  71. from guiLoop import guiLoop # https://gist.github.com/niccokunzmann/8673951
  72.  
  73. @guiLoop
  74. def led_blink(argument):
  75. while 1:
  76. print("LED on " + argument)
  77. yield 0.5 # time to wait
  78. print("LED off " + argument)
  79. yield 0.5
  80.  
  81. app = QtGui.QApplication(sys.argv)
  82.  
  83. w = QtGui.QWidget()
  84. w.resize(250, 150)
  85. w.move(300, 300)
  86. w.setWindowTitle('Simple')
  87. w.show()
  88.  
  89. led_blink(w, 'shiny!')
  90.  
  91. sys.exit(app.exec_())
  92.  
  93. def Start(self):
  94. if not self.started:
  95. self.started = True
  96. self.StartLoop()
  97.  
  98. def Stop(self):
  99. if self.started:
  100. self.started = False
  101.  
  102. def StartLoop(self):
  103. DEBUG = 1
  104. while self.started:
  105. print "LED on "
  106. time.sleep(0.05)
  107. print "LED off "
  108. time.sleep(0.085)
  109. QtGui.qApp.processEvents()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement