示例#1
0
    grovepi.chainableRgbLed_init(rgbLEDPort, num_of_leds)
    
    # Create threading object
    # radio_timer = MyThreading(5400, kill_mplayer)
    rgbled_timer = MyThreading(40, return_color, ())
    
    # Init mplayer
    kill_mplayer()
    
    # start up blink
    startup_blink = [7,6,5,4,3,2,1,0,7]
    for i in startup_blink:
        grovepi.chainableRgbLed_test(rgbLEDPort, num_of_leds, i)
        time.sleep(.1)
    
    [new_val, encoder_val] = grovepi.encoderRead()
    
    if encoder_val == 0:
        color_rgb = [0, 0, 0]
    else:
        color_rgb = [255, 0, 0]

    grovepi.storeColor(color_rgb[0], color_rgb[1], color_rgb[2])
    grovepi.chainableRgbLed_pattern(rgbLEDPort, thisLedOnly, 0)
    
    # recieve SIGTERM
    signal.signal(signal.SIGTERM, signal_term_handler)
    
    while True:
        try:
            # Encoder
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

# USAGE
#
# Connect the grove encoder to D2 on the GrovePi.
# You can send'run_in_bk=1' as a parameter, e.g. grovepi.encoderRead(run_in_bk=1) to run the encoder code in the background on the GrovePi. This allows you to use other functions such as digitalRead to run with the encoder read running in the background
#
# the fist byte is 1 for a new value and 0 for old values
# second byte is encoder positon from 1 to 24

import time
import grovepi

print "Reading from the encoder"
while True:
    try:
        [new_val, encoder_val] = grovepi.encoderRead(run_in_bk=1)
        if new_val:
            print encoder_val
        time.sleep(.5)

    except IOError:
        print("Error")
示例#3
0
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

# USAGE
#
# Connect the grove encoder to D2 on the GrovePi.
# the fist byte is 1 for a new value and 0 for old values
# second byte is encoder positon from 1 to 24

import time
import grovepi
import atexit

atexit.register(grovepi.encoder_dis)

print("Reading from the encoder")
grovepi.encoder_en()
while True:
    try:
        [new_val, encoder_val] = grovepi.encoderRead()
        if new_val:
            print(encoder_val)
        time.sleep(.5)

    except IOError:
        print("Error")
示例#4
0
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

# USAGE
#
# Connect the grove encoder to Port 2 on the GrovePi. The encoder only works on that port
# You can send'run_in_bk=1' as a parameter, e.g. grovepi.encoderRead(run_in_bk=1) to run the encoder code in the background on the GrovePi. This allows you to use other functions such as digitalRead to run with the encoder read running in the background
#
# the fist byte is 1 for a new value and 0 for old values
# second byte is encoder positon from 1 to 24

import time
import grovepi

print "Reading from the encoder"
while True:
    try:
		[new_val,encoder_val] = grovepi.encoderRead(run_in_bk=1)
		if new_val:
			print encoder_val
		time.sleep(.5) 

    except IOError:
        print ("Error")
示例#5
0
THE SOFTWARE.
'''

# USAGE
#
# Connect the grove encoder to D2 on the GrovePi.
# The encoder values go from 0 up to 32
# (although these can be subsequently changed by utilizing a different parameter for the encoder_en function)

import time
import grovepi

print("Reading from the Grove Encoder")

# default pin is 2 and default number of steps is 32
grovepi.encoder_en()

time_to_run = 10  # 10 seconds
start = time.time()  # current time in seconds
old_val = 0

while start + time_to_run > time.time():

    # defaults to pin 2
    new_val = grovepi.encoderRead()
    if old_val != new_val:
        print("{:3d}/32 position".format(new_val))
        old_val = new_val

# and disable the interrupt on pin 2
grovepi.encoder_dis()