(rgbPin=None,size=0)
| 3 | from pydos_rgb import PyDOS_rgb |
| 4 | |
| 5 | def rgbrainbow(rgbPin=None,size=0): |
| 6 | Pydos_rgb = PyDOS_rgb(rgbPin,size) |
| 7 | |
| 8 | if Pydos_rgb.size > 0: |
| 9 | # attempt to balance colors |
| 10 | MAXRED = 120 |
| 11 | MAXGREEN = 165 |
| 12 | MAXBLUE = 255 |
| 13 | |
| 14 | # Cycle colours. |
| 15 | icolor = 0 |
| 16 | transition = [-4,1,2,-1,4,1,-2,-1] |
| 17 | cmnd = "" |
| 18 | steps = 100 |
| 19 | r = 0 |
| 20 | g = 0 |
| 21 | b = 0 |
| 22 | |
| 23 | newSteps = 0 |
| 24 | print("listening... Enter value to alter speed, 'q' to quit") |
| 25 | |
| 26 | while cmnd.upper() != "Q": |
| 27 | |
| 28 | icolor = (icolor + 1) % 8 |
| 29 | |
| 30 | for k in range(steps): |
| 31 | if Pydos_ui.serial_bytes_available(): |
| 32 | cmnd = Pydos_ui.read_keyboard(1) |
| 33 | |
| 34 | if cmnd.upper() == "Q": |
| 35 | Pydos_rgb.fill((0,0,0)) |
| 36 | break |
| 37 | if cmnd == '\n': |
| 38 | if newSteps == 0: |
| 39 | print() |
| 40 | else: |
| 41 | steps = max(1,min(800,newSteps)) |
| 42 | print(" New STEP value: ",steps) |
| 43 | newSteps = 0 |
| 44 | if cmnd.isdigit(): |
| 45 | newSteps = (newSteps * 10) + int(cmnd) |
| 46 | print(cmnd,end="") |
| 47 | elif cmnd != None: |
| 48 | print(cmnd,end="") |
| 49 | |
| 50 | r += ((abs(transition[icolor]) & 1)/transition[icolor]) * (MAXRED / steps) |
| 51 | b += ((abs(transition[icolor]) & 2)/transition[icolor]) * (MAXBLUE / steps) |
| 52 | g += ((abs(transition[icolor]) & 4)/transition[icolor]) * (MAXGREEN / steps) |
| 53 | r = int(max(0,min(MAXRED,r))) |
| 54 | b = int(max(0,min(MAXBLUE,b))) |
| 55 | g = int(max(0,min(MAXGREEN,g))) |
| 56 | |
| 57 | Pydos_rgb.fill((r,g,b)) |
| 58 | |
| 59 | time.sleep(0.5/steps) |
| 60 | |
| 61 | #time.sleep(0.5) |
| 62 |
no test coverage detected