コード例 #1
0
def main():
    # Blue led on D4
    led = 4
    grovepi.pinMode(led, "OUTPUT")
    # Right sensor D8, Left sensor D7, Middle sensor D5
    # SIG,NC,VCC,GND
    ranger = 8
    left_power = 1.0
    right_power = 1.0

    bot = FourTronix()

    ledOn = 1
    starttime = time.time()
    while True:
        try:
            if ledOn == 1 and time.time() - starttime > 1.0:
                ledOn = 0
                starttime = time.time()
            elif ledOn == 0 and time.time() - starttime > 1.0:
                ledOn = 1
                starttime = time.time()

            grovepi.digitalWrite(led, ledOn)
            print("Version: ", grovepi.version())
            # Read distance value from Ultrasonic
            dist = grovepi.ultrasonicRead(ranger)
            print("dist: ", dist)
            if (dist < 80):
                left_power = adjust_power(left_power, 80 - dist)
            elif (dist > 100):
                right_power = adjust_power(right_power, 100 - dist)
            else:
                left_power = 1.0
                right_power = 1.0

            sleep(0.1)
            print(left_power, right_power)
            bot.move(left_power, right_power)

        except TypeError:
            print("Type Error")
        except IOError:
            print("IO Error")
コード例 #2
0
#!/usr/bin/env python
#
# GrovePi Example for checking the firmware for the GrovePi
#
# The GrovePi connects the Raspberry Pi and Grove sensors.  You can learn more about GrovePi here:  http://www.dexterindustries.com/GrovePi
#
# Have a question about this example?  Ask on the forums here:  http://www.dexterindustries.com/forum/?forum=grovepi
#
# LICENSE: 
# These files have been made available online through a [Creative Commons Attribution-ShareAlike 3.0](http://creativecommons.org/licenses/by-sa/3.0/) license.
#
# NOTE: If you get a version of 255.255.255, they try running the script again, if the issue still persists then you are using an old deprecated firmware
import grovepi

try:
    print "GrovePi has firmware version:", grovepi.version()

except KeyboardInterrupt:
    print "KeyboardInterrupt"
except IOError:
    print "Error"
コード例 #3
0
import grovepi

print grovepi.version()
コード例 #4
0
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

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.
'''
#
# NOTE: If you get a version of 255.255.255, they try running the script again, if the issue still persists then you are using an old deprecated firmware
import grovepi

try:
    print("GrovePi has firmware version: %s" % grovepi.version())

except KeyboardInterrupt:
    print("KeyboardInterrupt")
except IOError:
    print("Error")
コード例 #5
0
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

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.
'''
#
# NOTE: If you get a version of 255.255.255, they try running the script again, if the issue still persists then you are using an old deprecated firmware
import grovepi

try:
    print("GrovePi has firmware version: %s" %grovepi.version())

except KeyboardInterrupt:
    print ("KeyboardInterrupt")
except IOError:
   print ("Error")