Ejemplo n.º 1
0
    "G7": 3136,
    "GS7": 3322,
    "A7": 3520,
    "AS7": 3729,
    "B7": 3951,
    "C8": 4186,
    "CS8": 4435,
    "D8": 4699,
    "DS8": 4978
}

#   Test Tones
print('Testing our tones')
for k, v in tones.items():
    print('playing', k)
    pwmBuzzer.frequency = v
    pwmBuzzer.value = 0.8  # I don't know if this is a limitation of my crappy buzzer or pwm, but I cant use 1.0
    sleep(0.3)  # this is our tempo
    pwmBuzzer.value = 0

sleep(1)

#  Crappy jingle
print('Playing a crappy jingle')
for tone in [
        tones['CS3'],
        'P',
        tones['E3'],
        tones['CS3'],
        tones['CS3'],
        tones['F3'],
Ejemplo n.º 2
0
"""
from gpiozero import CPUTemperature, PWMOutputDevice
from time import sleep

#==Adjustable params===
t_max = 80.0
t_set = 65.0  # Desired set-point for CPU temperature in celcius
PIN_PWM = 18
PWM_MIN_HZ = 10  # Adjust to frequency with lowest fan whine
PWM_MIN_DC = 0.4  # Set this to the lowest duty cycle that is able to start fan
PWM_MAX_DC = 1.0  # continuously on
#======================

cpu = CPUTemperature()
fanPwm = PWMOutputDevice(pin=PIN_PWM)
fanPwm.frequency = PWM_MIN_HZ
fanPwm.value = 0

Kp = 1 / (1 * (t_max - t_set))  # Coefficient for P term
T_iter = 0.5  # PID loop time step
Ti = 10 * T_iter  # Integration time for I-term
Td = 2 * T_iter  # Derivative time for D-term
Nint = int(Ti / T_iter)
Nder = int(Td / T_iter)
Nmax = max(Nint, Nder)

errors = []  # for keeping Nmax last error terms. errors[0] is oldest term


def calc_error(temp_meas):
    """ Update error relative to t_set and store in errors for integration & derivation """
Ejemplo n.º 3
0
from gpiozero import PWMOutputDevice
from time import sleep

BUZZERPIN = 12

buzzer = PWMOutputDevice(BUZZERPIN)
buzzer.frequency = 5000
buzzer.value = 0.0


def buzz(frequency, period):
    buzzer.frequency = frequency
    buzzer.value = 0.5
    sleep(period)
    buzzer.value = 0.0


while True:
    buzz(3000, 2)
    sleep(1)
Ejemplo n.º 4
0
from gpiozero import PWMOutputDevice
from gpiozero import Robot
from time import sleep
from gpiozero import LED

led1 = LED(21)
#robot1 = Robot(right=(16, 20), left=(6,5))
robot1 = Robot(left=(16, 20), right=(6, 5))

PwmRight = PWMOutputDevice(19)
PwmLeft = PWMOutputDevice(13)

PwmRight.frequency = 1000
PwmRight.value = 0.25

PwmLeft.frequency = 1000
PwmLeft.value = 0.25

led1.on()
robot1.forward()
sleep(1)
led1.off()
robot1.left()
sleep(1)
#robot1.right()
sleep(1)
#robot1.backward()
led1.on()
sleep(1)
robot1.stop()
led1.off()