예제 #1
0
 def play_liberado(self):
     # Inicia buzzer
     #GPIO.setup(self.gpio, GPIO.OUT)
     buzz = PWM(self.porta, 500)  # initial frequency.
     buzz.start(50)  # Start buzzer pin with 50% duty ration
     time.sleep(0.2)  # delay a note for beat * 0.5s
     #    buzz.ChangeFrequency(550) # Change the frequency along the song note
     #    time.sleep(0.4) # delay a note for beat * 0.5s
     buzz.stop()  # Stop the buzzer
     super().ligar_porta()  # Set buzzer pin to High
예제 #2
0
    def __init__(self, pwm0, pwm1, pwm2, pwm3, a0, b0, a1, b1):
        """
		"""
        # self.mux = MCP230XX(0x20, 16, 1)
        #
        # for pin in range(0, 15):
        # 	self.mux.config(pin, GPIO.OUT)

        # this can be:
        # BOARD -> Board numbering scheme. The pin numbers follow the pin numbers on header P1.
        # BCM -> Broadcom chip-specific pin numbers.
        GPIO.setmode(GPIO.BCM)  # Pi cover uses BCM pin numbers, GPIO.BCM = 11
        GPIO.setup([pwm0, pwm1, pwm2, pwm3], GPIO.OUT)  # GPIO.OUT = 0

        freq = 100.0  # Hz
        self.motor0 = PWM(pwm0, freq)
        self.motor1 = PWM(pwm1, freq)
        self.motor2 = PWM(pwm2, freq)
        self.motor3 = PWM(pwm3, freq)

        self.motor0.start(0)
        self.motor1.start(0)
        self.motor2.start(0)
        self.motor3.start(0)

        self.ctl = [a0, b0, a1, b1]

        GPIO.setup([a0, b0, a1, b1], GPIO.OUT)  # GPIO.OUT = 0
        # self.a0 = a0
        # self.b0 = b0
        # self.a1 = a1
        # self.b1 = b1

        # GPIO.output(self.a0, GPIO.LOW)
        # GPIO.output(self.b0, GPIO.LOW)
        # GPIO.output(self.a1, GPIO.LOW)
        # GPIO.output(self.a1, GPIO.LOW)

        for pin in self.ctl:
            GPIO.output(pin, GPIO.LOW)
예제 #3
0
파일: rpiLed.py 프로젝트: SarathM1/RPi
def led_breathe(pin_no):
    """
	Fn to vary the duty cycle to   
	dim/brighten the leds
	"""
    pwm = PWM(pin_no, 100)  # create object for PWM on port pin_no at 100 Hertz
    pwm.start(0)  # start led on 0 percent duty cycle (off)
    for i in range(101):
        pwm.ChangeDutyCycle(
            i)  # Increase duty cycle from 0% to 100% (step by 1)
        time.sleep(0.03)
    for i in range(100, -1, -1):
        pwm.ChangeDutyCycle(
            i)  # Decrease duty cycle from 0% to 100% (step by 1)
        time.sleep(0.03)
    time.sleep(1)
    pwm.stop()  # stop the PWM output
예제 #4
0

def stop(duty=0):
    straight()
    output(20, LOW)
    output(22, LOW)
    return default_response()


def default(duty=0):
    print "Command not found"

stop(0)
straight(0)

p = PWM(17, 90)
p2 = PWM(13, 90)
p.start(50)
p2.start(100)

commands_dict = {"b": backward,
                 "f": forward,
                 "s": stop,
                 "r": right,
                 "l": left,
                 "st": straight}


def move(request):
    commands_dict.get(request.matchdict['direction'], default)()
    return default_response()