Beispiel #1
0
 def read(self):
     '''
     tries to get a value up to 10 times.
     As soon as a valid value is read, it returns either 0 or 1
     returns -1 after 10 unsuccessful tries
     '''
     okay = False
     error_count = 0
     while not okay and error_count < 10:
         try:
             rtn = int(gopigo.digitalRead(self.getPortID()))
             okay = True
         except:
             error_count += 1
     if error_count > 10:
         return -1
     else:
         return rtn
Beispiel #2
0
 def read(self):
     '''
     tries to get a value up to 10 times.
     As soon as a valid value is read, it returns either 0 or 1
     returns -1 after 10 unsuccessful tries
     '''
     okay = False
     error_count = 0
     while not okay and error_count < 10:
         try:
             rtn = int(gopigo.digitalRead(self.getPortID()))
             okay = True
         except:
             error_count += 1
     if error_count > 10:
         return -1
     else:
         return rtn
Beispiel #3
0
def wait_for_button():
	gopigo.stop()
	while (gopigo.digitalRead(button_pin) != 1):
		try:
			time.sleep(.5)
		except IOError:
			print ("Error")
	print "Button pressed!"
	
	gopigo.set_speed(gopigo_speed)
	distance = 100
	while (distance > distance_from_body):
		try:
			distance = gopigo.us_dist(distance_sensor_pin)
			print ("Distance: " + str(distance))
			time.sleep(.1)
			gopigo.fwd()
		except IOError:
			print ("Error")
	
	gopigo.stop()
	
	sound("Hello!")
Beispiel #4
0
def wait_for_button():
    gopigo.stop()
    while (gopigo.digitalRead(button_pin) != 1):
        try:
            time.sleep(.5)
        except IOError:
            print("Error")
    print "Button pressed!"

    gopigo.set_speed(gopigo_speed)
    distance = 100
    while (distance > distance_from_body):
        try:
            distance = gopigo.us_dist(distance_sensor_pin)
            print("Distance: " + str(distance))
            time.sleep(.1)
            gopigo.fwd()
        except IOError:
            print("Error")

    gopigo.stop()

    sound("Hello!")
Beispiel #5
0
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.
'''

import time
import gopigo

# Connect the Grove Button to digital port D10 or A1
#   The pin should be 15 for A11 port and 10 for the D10 digital port or you can call the analogPort or digitalPort definitions from the GoPiGo library
#   The button won't work on any other port

# button_pin = gopigo.analogPort
button_pin = 11

gopigo.pinMode(button_pin,"INPUT")

while True:
    try:
        print (gopigo.digitalRead(button_pin))
        time.sleep(.5)

    except IOError:
        print ("Error")
Beispiel #6
0
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.
'''

import time
import gopigo

# Connect the Grove Button to digital port D10 or A1
#   The pin should be 15 for A11 port and 10 for the D10 digital port or you can call the analogPort or digitalPort definitions from the GoPiGo library
#   The button won't work on any other port

# button_pin = gopigo.analogPort
button_pin = 11

gopigo.pinMode(button_pin, "INPUT")

while True:
    try:
        print(gopigo.digitalRead(button_pin))
        time.sleep(.5)

    except IOError:
        print("Error")
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.
'''

import time
import gopigo

# Connect the Grove PIR motion sensor to digital port D10 or A1
#   The pin should be 15 for A11 port and 10 for the D10 digital port or you can call the analogPort or digitalPort definitions from the GoPiGo library
#   The sensor won't work on any other port

# motion_sensor_pin = gopigo.digitalPort
motion_sensor_pin = gopigo.analogPort

gopigo.pinMode(motion_sensor_pin,"INPUT")

while True:
    try:
        print (gopigo.digitalRead(motion_sensor_pin))
        time.sleep(.5)

    except IOError:
        print ("Error")
Beispiel #8
0
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.
'''

import time
import gopigo

# Connect the Grove PIR motion sensor to digital port D10 or A1
#   The pin should be 15 for A11 port and 10 for the D10 digital port or you can call the analogPort or digitalPort definitions from the GoPiGo library
#   The sensor won't work on any other port

# motion_sensor_pin = gopigo.digitalPort
motion_sensor_pin = gopigo.analogPort

gopigo.pinMode(motion_sensor_pin, "INPUT")

while True:
    try:
        print(gopigo.digitalRead(motion_sensor_pin))
        time.sleep(.5)

    except IOError:
        print("Error")
Beispiel #9
0
def digitalRead(kargs):
    r = {'return_value': gopigo.digitalRead(int(kargs['pin']))}
    return r