コード例 #1
0
ファイル: motorfuncs.py プロジェクト: survinderpal/RDuD2
def turn_left(angle, vel):
    """
    Turns to the left according to angle (delay)
    """
    Arduino.digitalWrite(dirA, Arduino.HIGH)
    Arduino.digitalWrite(dirB, Arduino.LOW)
    Arduino.analogWrite(speedA, vel)
    Arduino.analogWrite(speedB, Arduino.LOW)
    Arduino.delay(angle)
コード例 #2
0
ファイル: motorfuncs.py プロジェクト: survinderpal/RDuD2
def reverse(dist, vel):
    """
    Move backwards for dist (time) at vel (motor speed)
    """
    Arduino.digitalWrite(dirA, Arduino.LOW)
    Arduino.digitalWrite(dirB, Arduino.LOW)
    Arduino.analogWrite(speedA, vel)
    Arduino.analogWrite(speedB, vel)
    Arduino.delay(dist)
コード例 #3
0
ファイル: motorfuncs.py プロジェクト: survinderpal/RDuD2
def forward(dist, vel):
    """
    Move forward for dist (time) at vel (motor speed)
    """
    Arduino.digitalWrite(dirA, Arduino.HIGH)
    Arduino.digitalWrite(dirB, Arduino.HIGH)
    Arduino.analogWrite(speedA, vel)
    Arduino.analogWrite(speedB, vel)
    Arduino.delay(dist)
コード例 #4
0
ファイル: sensorfuncs.py プロジェクト: survinderpal/RDuD2
def read_sensors():
    """
    Reads each of the Sharp sensors are returns a list of analog readings
    in order: front, right, left, rear
    """
    reading = []
    for i in [FrontBump, RightBump, LeftBump, RearBump]:
        reading.append(Arduino.analogRead(i))
        Arduino.delay(1)
    return reading
コード例 #5
0
ファイル: motorfuncs.py プロジェクト: survinderpal/RDuD2
def rot_ccw(angle, vel):
    """
    Spins to the left according to angle (delay),
    then stops the motors
    """
    Arduino.digitalWrite(dirA, Arduino.HIGH)
    Arduino.digitalWrite(dirB, Arduino.LOW)
    Arduino.analogWrite(speedA, vel)
    Arduino.analogWrite(speedB, vel)
    Arduino.delay(angle)
コード例 #6
0
    def __fetchAddress(self):
        ds_address = self.__ds.search()

        if ds_address == "1":
            return False

        self.__ds.reset()
        self.__ds.select(ds_address)
        self.__ds.write(0x44, 1)
        Arduino.delay(700)
        present = self.__ds.reset()
        self.__ds.select(ds_address)
        self.__ds.write(0xBE)
        return True
コード例 #7
0
ファイル: nanpy_avoider.py プロジェクト: russb78/RDuD2
def debug():
    """
    If lock switch is in the locked position stop motors and give sensor feedback instead
    """
    stop()
    reading = read_sensors()
    Arduino.delay(5)
    if reading[0] > frontTrigger:
        print "Front bump detected!"
    elif reading[1] > sideTrigger:
        print "Right bump detected!"
    elif reading[2] > sideTrigger:
        print "Left bump detected!"
    elif reading[3] > rearTrigger:
        print "Rear bump detected!"
    else:
        print "Front:", reading[0], " | Right:", reading[1], " | Left:", reading[2], " | Rear:", reading[3]
        sleep(0.1)
コード例 #8
0
def get_pots():
	"""
	Grab a reading from each of the pot pins and 
	send it to a tuple to be read by the colour mixer
	"""
	r = Arduino.analogRead(pot_r_Pin) / 4
	Arduino.delay(1)
	g = Arduino.analogRead(pot_g_Pin) / 4
	Arduino.delay(1)
	b = Arduino.analogRead(pot_b_Pin) / 4
	Arduino.delay(1)
	return r, g, b
コード例 #9
0
def get_pots():
	"""
	Grab a reading from each of the pot pins and 
	send it to a tuple to be read by the colour mixer
	"""
	r = Arduino.analogRead(pot_r_Pin) / 4
	Arduino.delay(1)
	g = Arduino.analogRead(pot_g_Pin) / 4
	Arduino.delay(1)
	b = Arduino.analogRead(pot_b_Pin) / 4
	Arduino.delay(1)
	return r, g, b
コード例 #10
0
ファイル: blink.py プロジェクト: bminton3/pi
#!/usr/bin/env python

# Author: Andrea Stagi <*****@*****.**>
# Description: keeps your led blinking
# Dependencies: None

from nanpy import Arduino

Arduino.pinMode(13, Arduino.OUTPUT)

for i in range(10000):
    Arduino.digitalWrite(13, (i + 1) % 2)
    Arduino.delay(200)

コード例 #11
0
ファイル: sensorfuncs.py プロジェクト: survinderpal/RDuD2
    if bump > sideTrigger:
        return True
    else:
        return False


def rear_bump():
    bump = Arduino.analogRead(RearBump)
    if bump > rearTrigger:
        return True
    else:
        return False


def read_sensors():
    """
    Reads each of the Sharp sensors are returns a list of analog readings
    in order: front, right, left, rear
    """
    reading = []
    for i in [FrontBump, RightBump, LeftBump, RearBump]:
        reading.append(Arduino.analogRead(i))
        Arduino.delay(1)
    return reading


while DEBUG:  # for sensor debugging purposes only
    reading = read_sensors()
    Arduino.delay(1)
    print "Front:", reading[0], " | Right:", reading[1], " | Left:", reading[2], " | Rear:", reading[3]
コード例 #12
0
A.digitalWrite(4, A.LOW)

# LOOP
while True:
    sensorVal = A.analogRead(SENSOR_PIN_A0)
    voltage = (sensorVal / 1024.0) * 5.0
    temperature = (voltage - 0.5) * 100
    print("Sensor value: " + str(sensorVal) + ", Volts: " + str(voltage)  +", Degrees C: " + str(temperature) + ".")
    
    # if the current temperature is lower than the baseline turn off all LEDs
    if temperature < BASELINE_TEMP:
        A.digitalWrite(2, A.LOW)
        A.digitalWrite(3, A.LOW)
        A.digitalWrite(4, A.LOW)
    # if the temperature rises 2-4 degrees, turn an LED on 
    elif (temperature >= BASELINE_TEMP + 2 and temperature < BASELINE_TEMP + 4):
        A.digitalWrite(2, A.HIGH)
        A.digitalWrite(3, A.LOW)
        A.digitalWrite(4, A.LOW)
    # if the temperature rises 4-6 degrees, turn a second LED on  
    elif (temperature >= BASELINE_TEMP + 4 and temperature < BASELINE_TEMP + 6):
        A.digitalWrite(2, A.HIGH)
        A.digitalWrite(3, A.HIGH)
        A.digitalWrite(4, A.LOW)
    # if the temperature rises more than 6 degrees, turn all LEDs on
    elif (temperature >= BASELINE_TEMP + 6):
        A.digitalWrite(2, A.HIGH)
        A.digitalWrite(3, A.HIGH)
        A.digitalWrite(4, A.HIGH)
    A.delay(1)
コード例 #13
0
#!/usr/bin/env python

# Author: Andrea Stagi <*****@*****.**>
# Description: keeps your led blinking
# Dependencies: None

from nanpy import Arduino
sys.path.append('/home/pi/Desktop/nanpy-0.8/firmware/ArduinoClass.h')

Arduino.pinMode(4, Arduino.OUTPUT)

for i in range(10000):
    Arduino.digitalWrite(4, (i + 1) % 2)
    Arduino.delay(1000)

コード例 #14
0
#!/usr/bin/env python

# Author: Scott Ellis
# Basic Digital Read
# turns on and off a light emitting diode(LED) connected to digital  
# pin 13, when pressing a pushbutton attached to pin 5. 
# Dependencies: nanpy 0.7

from nanpy import Arduino

sensorButton = Arduino.digitalRead(5)
Arduino.pinMode(sensorButton, Arduino.INPUT)

ledPin = 13; 
Arduino.pinMode(ledPin, Arduino.OUTPUT)

while True:
    sensorButton = Arduino.digitalRead(5)
    print("sensor value: %d" % sensorButton)
    if (sensorButton == True):
        Arduino.digitalWrite(ledPin, Arduino.HIGH)
    else:
        Arduino.digitalWrite(ledPin, Arduino.LOW)
    Arduino.delay(100)
コード例 #15
0
__license__ = 'None'

from nanpy import Arduino as A
switchstate = 0

# SETUP:
A.pinMode(3, A.OUTPUT)
A.pinMode(4, A.OUTPUT)
A.pinMode(5, A.OUTPUT)

A.pinMode(2, A.INPUT)

# LOOP:
while True:
    switchState = A.digitalRead(2)
    if switchState == A.LOW:
        A.digitalWrite(3, A.HIGH) # turn the green LED on pin 3 on
        A.digitalWrite(4, A.LOW)  # turn the red LED on pin 4 off
        A.digitalWrite(5, A.LOW)  # turn the red LED on pin 5 off
    else:
        A.digitalWrite(3, A.LOW);  # turn the green LED on pin 3 off
        A.digitalWrite(4, A.LOW);  # turn the red LED on pin 4 off
        A.digitalWrite(5, A.HIGH); # turn the red LED on pin 5 on
        
        # wait for a quarter second before changing the light
        A.delay(250);
        A.digitalWrite(4, A.HIGH); #// turn the red LED on pin 4 on
        A.digitalWrite(5, A.LOW);  #// turn the red LED on pin 5 off
        
        # wait for a quarter second before changing the light
        A.delay(250);
コード例 #16
0
def get_b():
	b_val = Arduino.analogRead(pot_b_Pin) / 4
	Arduino.delay(1)
	return b_val
コード例 #17
0
def get_g():
	g_val = Arduino.analogRead(pot_g_Pin) / 4
	Arduino.delay(1)
	return g_val
コード例 #18
0
def get_r():
	r_val = Arduino.analogRead(pot_r_Pin) / 4
	Arduino.delay(1)
	return r_val
コード例 #19
0
ファイル: arduino.py プロジェクト: mikinty/frigid
from nanpy import Arduino as A

# setup
A.pinMode(1, A.OUTPUT)

while True:
    A.digitalWrite(1, HIGH)
    A.delay(400)
    A.digitalWrite(1, LOW)
    A.delay(400)