Created
October 23, 2014 05:09
-
-
Save wintryKat/2a0d884383d76a38ba68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| from time import sleep | |
| import os | |
| PIN_LED_R = 23 | |
| PIN_LED_G = 25 | |
| PIN_LED_B = 18 | |
| PB_DEVICE = '/dev/pi-blaster' | |
| def interface(stmt): | |
| pb = os.open(PB_DEVICE, os.O_SYNC|os.O_WRONLY|os.O_TRUNC) | |
| try: | |
| os.write(pb, stmt + '\n') | |
| except: | |
| raise | |
| finally: | |
| os.close(pb) | |
| def capture(pin): | |
| setvalue(pin, 1) | |
| def release(pin): | |
| setvalue(pin, 0) | |
| interface('release {pin:d}'.format(pin=pin)) | |
| def setvalue(pin, value): | |
| if value >= 0 and value <= 1: | |
| interface('{pin:d}={value:f}'.format(pin=pin, value=value)) | |
| else: | |
| raise ValueError('Value must be between 0 and 1 inclusive') | |
| if __name__ == '__main__': | |
| capture(PIN_LED_R) | |
| capture(PIN_LED_G) | |
| capture(PIN_LED_B) | |
| i = 0 | |
| try: | |
| while True: | |
| for j, p in [(3, PIN_LED_R), (4, PIN_LED_G), (5, PIN_LED_B)]: | |
| v = math.fabs(math.sin((i+(30*j))/30.0)) | |
| print('pin{pin} value={value}'.format(pin=p, value=v)) | |
| setvalue(p, v) | |
| i += 1 | |
| sleep(0.0167) | |
| except: | |
| raise | |
| finally: | |
| release(PIN_LED_R) | |
| release(PIN_LED_G) | |
| release(PIN_LED_B) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment