コード例 #1
0
ファイル: pwm_test.py プロジェクト: pdsherman/RaspberryPi
         newVal = showDisplay(reply)
         newrgbVal = rgb_led.setRGB(newVal)
      elif reply == 5: #Fade to random color
         showDisplay(reply)
         #newrgbVal = rgb_led.fadeToNewColor(randrange(256), randrange(256), randrange(256))
         for i in range(16):
            rgb_led.usePreSetColor(i)
            time.sleep(0.75)
         newrgbVal = rgb_led.setRGB(0)
      elif reply == 6: #Changing Flashing Rate of LEDs
         flashRate = showDisplay(reply)
         rgb_led.setBPM(flashRate)
         continue
      elif reply == 7: #Exit Program 
         os.system('clear')
         break
      else: #Show main menu
         continue

      #Update Saved RGB value and color values
      if newrgbVal != -1:
            rgbVal = newrgbVal
            colors = [rgbVal>>16, (rgbVal>>8)&0xFF, rgbVal&0xFF]

# main code
colors = [0, 0, 0]
rgbVal = 0
flashRate = 60
rgb_led.init_PWM(initDutyCycle = [0]*3, flashRate=60)
menu()
コード例 #2
0
ファイル: rgb_main.py プロジェクト: pdsherman/RaspberryPi
posGreen = 1
posBlue  = 2
posClr   = 3
posBPM   = 4
posSwt   = 5

mask_manual = 0b01
mask_ClrWhl = 0b10

bpmMax = 230
bpmMin = 30
diffMin = 2
prevBPM_analog = 0

#Intialize Hardware / Variables
rgb_led.init_PWM(initDutyCycle = [0]*3, flashrate = 0)
rgb_led.initSPI(23, 24, 25)


"""
Function: scaleBPM
------------------
Description: takes analog value (0-1024) and scales to 
corresponding beats per minute
"""
def scaleBPM(currBPM_analog):

   diff = abs(currBPM_analog - prevBPM_analog) 
   if(diff > diffMin):
      currBPM = floor( (currBPM_analog / 1024.0) * (bpmMax-bpmMin) + bpmMin )
      prevBPM_analog = currBPM_analog