def start_stream(sensor_pin=14, fs=10): """ Reads values from analog pin 14 and forwards them to a LSL-stream. """ # Setup the LSL stream uuid = binascii.b2a_hex(os.urandom(3)) stream_info = lsl.StreamInfo('luminosity', 'analog', 1, fs, 'float32', uuid) stream_outlet = lsl.StreamOutlet(stream_info) # Setup GPIO gpio = GPIO(debug=False) gpio.pinMode(sensor_pin, gpio.ANALOG_INPUT) interval = 1.0 / fs try: while True: value = gpio.analogRead(sensor_pin) stream_outlet.push_sample([value]) time.sleep(interval) except KeyboardInterrupt: print("\nCleaning up...") gpio.cleanup()
def start_stream(sensor_pin=14, fs=10): # Setup the LSL stream uuid = binascii.b2a_hex(os.urandom(3)) stream_info = lsl.StreamInfo('luminosity', 'analog', 1, fs, 'float32', uuid) stream_outlet = lsl.StreamOutlet(stream_info) # Setup GPIO gpio = GPIO(debug=False) gpio.pinMode(sensor_pin, gpio.ANALOG_INPUT) interval = 1.0 / fs try: while True: value = gpio.analogRead(sensor_pin) stream_outlet.push_sample([value]) time.sleep(interval) except KeyboardInterrupt: print("\nCleaning up...") gpio.cleanup()
# Set pin 3 to be used as a PWM pin. print 'Setting up pin %d' % pin gpio.pinMode(pin, gpio.PWM) print 'Fading pin %d now...' % pin try: while(True): # Write brightness to the pin. The value must be between 0 and 255. gpio.analogWrite(pin, brightness) # Increment or decrement the brightness. brightness = brightness + fadeAmount # If the brightness has reached its maximum or minimum value swap # fadeAmount sign so we can start fading the led on the other direction. if brightness == 0 or brightness == 255: fadeAmount = -fadeAmount # Sleep for a while. time.sleep(0.03) # When you get tired of seeing the led fading kill the loop with Ctrl-C. except KeyboardInterrupt: # Leave the led turned off. print '\nCleaning up...' gpio.analogWrite(pin, 0) # Do a general cleanup. Calling this function is not mandatory. gpio.cleanup()