コード例 #1
0
ファイル: LE.py プロジェクト: normansaez/bbb-darc
def turn_on_pwm(pin):
    PWM.start(pin, 50)
    PWM.set_duty_cycle(pin, 25.5)
    PWM.set_frequency(pin, 10)
    print sys._getframe().f_code.co_name,
    print(' '+pin)
    raw_input('press a key to continue')
コード例 #2
0
ファイル: xibb.py プロジェクト: MrYsLab/xideco
    def play_tone(self):
        """
        This method will play a tone using PWM.
        """

        # clear out any residual problem strings

        self.last_problem = '5-0\n'

        pin = self.validate_pin(self.pwm_pins)
        if pin == 99:
            self.last_problem = '5-1\n'
            return

        # get pin information
        index = self.pwm_pins.index(pin)
        pin_entry = self.pwm_pin_states[index]

        if not pin_entry['enabled']:
            self.last_problem = '5-2\n'
            return

        frequency = int(self.payload['frequency'])
        duration = float(self.payload['duration']) / 1000

        PWM.set_duty_cycle(pin, 50)

        PWM.set_frequency(pin, frequency)

        if duration == 0:
            return

        time.sleep(duration)

        PWM.set_duty_cycle(pin, 0.0)
コード例 #3
0
	def jouer_note(self,note, duty):
		PWM.set_frequency("P9_14", note)
		PWM.set_duty_cycle("P9_14", duty)
		time.sleep(0.5)
		PWM.set_duty_cycle("P9_14", 0)
		time.sleep(0.3)
		PWM.set_duty_cycle("P9_14", duty)
コード例 #4
0
ファイル: flow.py プロジェクト: dotsonlab/AWSC-Toilet
 def triggerStepper(self):
     time.sleep(0.5)
     PWM.start("P9_16", 25, 100, 1)
     time.sleep(2)
     PWM.set_frequency("P9_16", 250)
     time.sleep(90)
     PWM.stop("P9_16")
     PWM.cleanup()
コード例 #5
0
 def setDutyFrequency(self, dutyFrequency):
     """Set device duty frequency."""
     if (dutyFrequency in self._settings['dutyFrequencies']):
         self._dutyFrequency = dutyFrequency
         PWM.set_frequency(self._pin, int(
             self._dutyFrequency[:-3]))  # Set the duty frequency
         self._update = True  # Raise update flag
     else:
         raise ValueError(
             'duty frequency {} is not allowed'.format(dutyFrequency))
コード例 #6
0
def spin_left(duty):
    PWM.set_duty_cycle(right, duty)
    PWM.set_duty_cycle(left, duty)
    PWM.set_frequency(right, 200)
    PWM.set_frequency(left, 200)

    GPIO.output("P8_14", GPIO.LOW)
    GPIO.output("P8_15", GPIO.HIGH)
    GPIO.output("P8_16", GPIO.HIGH)
    GPIO.output("P8_17", GPIO.LOW)
    return None
コード例 #7
0
 def sound_game(self, audio_frequency): 
     """ Control the I/O of the sound """
     PWM.start(self.piezzo, self.init_duty)   #Starts with 66% of 5V, 3.3V supply to piezzo buzzer
     
     # Play the sound
     for frequency in audio_frequency:
         PWM.set_frequency(self.piezzo, frequency)
         time.sleep(self.sound_delay)
         
     # Stop the sound
     PWM.stop(self.piezzo)
コード例 #8
0
def forward():
    PWM.set_duty_cycle(right, 50)
    PWM.set_duty_cycle(left, 50)
    PWM.set_frequency(right, 75)
    PWM.set_frequency(left, 75)

    GPIO.output("P8_14", GPIO.LOW)
    GPIO.output("P8_15", GPIO.HIGH)
    GPIO.output("P8_16", GPIO.LOW)
    GPIO.output("P8_17", GPIO.HIGH)
    return None
コード例 #9
0
ファイル: robot.py プロジェクト: ayoubserti/BBB-Bot
 def __speaker(self):
     if self.SPEAKER:
         return
     self.SPEAKER = True
     PWM.start(self.SPEAKER_PWM, 50, 3000)
     for dir in [-1,2]:
         for x in range(3,20):
             PWM.set_frequency(self.SPEAKER_PWM, 3000 + (dir * x * 100))
             sleep(0.05)
     PWM.stop(self.SPEAKER_PWM)
     self.SPEAKER = False
     return
コード例 #10
0
def setup_io_init():
	logger.info("Initializing IO")
	PWM.start(PUMP, 0)
	PWM.set_frequency(PUMP, 1000)
	water_pump(0)
	GPIO.setup(HEATER,GPIO.OUT)
	GPIO.setup(LAMP_1,GPIO.OUT)
	GPIO.setup(LAMP_2,GPIO.OUT)	
	lamp(False, LAMP_1)
	lamp(False, LAMP_2)
	heater(False)
	ADC.setup()
コード例 #11
0
ファイル: robot.py プロジェクト: silver2row/BBB-Bot
 def __speaker(self):
     if self.SPEAKER:
         return
     self.SPEAKER = True
     PWM.start(self.SPEAKER_PWM, 50, 3000)
     for dir in [-1, 2]:
         for x in range(3, 20):
             PWM.set_frequency(self.SPEAKER_PWM, 3000 + (dir * x * 100))
             sleep(0.05)
     PWM.stop(self.SPEAKER_PWM)
     self.SPEAKER = False
     return
コード例 #12
0
def jouer_note(note, duty):
    PWM.set_frequency("P9_22", note)
    PWM.set_duty_cycle("P9_22", duty)
    time.sleep(0.5)
    PWM.set_duty_cycle("P9_22", 0)
    '''    
    lst = range(duty, -1, -1)
    for i in lst:
        PWM.set_duty_cycle("P9_22", i)
        time.sleep(0.008)
    '''
    time.sleep(0.3)
    PWM.set_duty_cycle("P9_22", duty)
コード例 #13
0
ファイル: square2.py プロジェクト: amitasviper/sample
def takeInput():
        global freq, dutyCycle, pin
        while(True):
                choice = int(raw_input("1.Change Frequency 2.Change DutyCycle 3.EXIT: "))
                if choice == 1:
                        freq = int(raw_input("Enter Frequency: "))
                        PWM.set_frequency(pin,freq)
                elif choice == 2:
                        dutyCycle = int(raw_input("Enter Duty Cycle: "))
                        PWM.set_duty_cycle(pin,dutyCycle)
                elif choice == 3:
                        break
                else:
                        print "Invalid choice! Try Again"
コード例 #14
0
ファイル: square2.py プロジェクト: amitasviper/Assignments
def takeInput():
    global freq, dutyCycle, pin
    while (True):
        choice = int(
            raw_input("1.Change Frequency 2.Change DutyCycle 3.EXIT: "))
        if choice == 1:
            freq = int(raw_input("Enter Frequency: "))
            PWM.set_frequency(pin, freq)
        elif choice == 2:
            dutyCycle = int(raw_input("Enter Duty Cycle: "))
            PWM.set_duty_cycle(pin, dutyCycle)
        elif choice == 3:
            break
        else:
            print "Invalid choice! Try Again"
コード例 #15
0
def timed_backward(t,duty):
    PWM.set_duty_cycle(right, duty)
    PWM.set_duty_cycle(left, duty)
    PWM.set_frequency(right, 75)
    PWM.set_frequency(left, 75)

    GPIO.output("P8_14", GPIO.HIGH)
    GPIO.output("P8_15", GPIO.LOW)
    GPIO.output("P8_16", GPIO.HIGH)
    GPIO.output("P8_17", GPIO.LOW)
    
    time.sleep(t)
    
    GPIO.output("P8_14", GPIO.LOW)
    GPIO.output("P8_16", GPIO.LOW)
    return None
コード例 #16
0
def getPWMWriteFun(pin):
    if(pin[0]=='P'):
        PWM.start(pin, 0)
        PWM.set_frequency(pin, pwm_freq)
        return partial(PWM.set_duty_cycle,pin)
    elif(pin[0]=='I'):
        l=self.pinB.rsplit("_")
        if ( l[2] in i2cMap):
            i2c=i2cMap[l[2]]
        else:
            i2c=Adafruit_I2C(l[2],1 , False)
            i2c.write8(PCA9685_MODE1, 0x01)
            time.sleep(0.05)
            i2cMap[l[2]]=i2c
        return partial(setI2CDutyCycle, i2c, l[3])
            
    elif (pin[0]=='D'):
        def funt(d):
            return d
        return partial(funt)        
    else
        exit(-1)
コード例 #17
0
def init_rover():
    GPIO.setup(channel_1_dir, GPIO.OUT)
    GPIO.setup(channel_2_dir, GPIO.OUT)
    GPIO.setup(channel_3_dir, GPIO.OUT)
    GPIO.setup(channel_4_dir, GPIO.OUT)
    GPIO.output(channel_1_dir, GPIO.HIGH)
    GPIO.output(channel_2_dir, GPIO.HIGH)
    GPIO.output(channel_3_dir, GPIO.LOW)
    GPIO.output(channel_4_dir, GPIO.LOW)
    PWM.start(channel_1_pwm, 0.0)
    PWM.start(channel_2_pwm, 0.0)
    PWM.start(channel_3_pwm, 0.0)
    PWM.start(channel_4_pwm, 0.0)
    time.sleep(0.2)
    PWM.set_frequency(channel_1_pwm, 250)
    PWM.set_frequency(channel_2_pwm, 250)
    PWM.set_frequency(channel_3_pwm, 250)
    PWM.set_frequency(channel_4_pwm, 250)
コード例 #18
0
ファイル: rover.py プロジェクト: BryanOrabutt/FPV_Rover
def init_rover():
	GPIO.setup(channel_1_dir, GPIO.OUT)
	GPIO.setup(channel_2_dir, GPIO.OUT)
	GPIO.setup(channel_3_dir, GPIO.OUT)
	GPIO.setup(channel_4_dir, GPIO.OUT)
	GPIO.output(channel_1_dir, GPIO.HIGH)
	GPIO.output(channel_2_dir, GPIO.HIGH)
	GPIO.output(channel_3_dir, GPIO.LOW)
	GPIO.output(channel_4_dir, GPIO.LOW)
	PWM.start(channel_1_pwm, 0.0)
	PWM.start(channel_2_pwm, 0.0)
	PWM.start(channel_3_pwm, 0.0)
	PWM.start(channel_4_pwm, 0.0)
	time.sleep(0.2)
	PWM.set_frequency(channel_1_pwm, 250)
	PWM.set_frequency(channel_2_pwm, 250)
	PWM.set_frequency(channel_3_pwm, 250)
	PWM.set_frequency(channel_4_pwm, 250)
コード例 #19
0
	def __init__(self,pin):
		PWM.start(pin, 50)
		PWM.set_frequency(pin, Fe)
		PWM.set_duty_cycle(pin,0)
コード例 #20
0
ファイル: bbpwmgen.py プロジェクト: makernexus/MN_CNC
        pulley = 2
        if h['pulley-A']:
            pulley = 0
        if h['pulley-B']:
            pulley = 1
        if h['pulley-C']:
            pulley = 2
        if h['pulley-D']:
            pulley = 3
        new_gear = h['gear-hi']
        new_speed = h['speed']
        new_direction = h['direction']
        if (pulley != old_pulley) or (new_gear != old_gear) or (
                new_speed != old_speed) or (new_direction != old_direction):
            old_gear = h['gear-hi']
            old_pulley = pulley
            old_speed = new_speed
            old_direction = new_direction
            ratio = (ratios[pulley])[new_gear]
            h['vfd-hz'] = new_speed / 60
            # Kludge. cannot set freq to 0, but at 1 HZ the VFD will stop
            speed = new_speed
            if speed == 0:
                speed = 1
            PWM.set_frequency(pin_name, speed * ratio)
            h['vfd-direction'] = new_direction ^ (not new_gear)
except KeyboardInterrupt:
    PWM.stop(pin_name)
    PWM.cleanup()
    raise SystemExit
コード例 #21
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("P9_14", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_14", -1)
         PWM.cleanup()            
コード例 #22
0
def marche_imperiale():
    #PWM.start("P9_22", 50)
    
    jouer_note(sol, 50)
    jouer_note(sol, 50)
    jouer_note(sol, 50)
    
    PWM.set_frequency("P9_22", mi)
    time.sleep(0.45)
    PWM.set_frequency("P9_22", si)
    time.sleep(0.15)
    PWM.set_frequency("P9_22", sol)
    time.sleep(0.6)
    PWM.set_frequency("P9_22", mi)
    time.sleep(0.45)
    PWM.set_frequency("P9_22", si)
    time.sleep(0.15)
    PWM.set_frequency("P9_22", sol)
    time.sleep(0.45)
    
    PWM.set_duty_cycle("P9_22", 0)
    time.sleep(0.6)
    jouer_note(re,50)
    jouer_note(re,50)
    jouer_note(re,50)
    PWM.set_frequency("P9_22", mi)
    time.sleep(0.45)
    PWM.set_frequency("P9_22", si)
    
    time.sleep(0.15)
    PWM.set_frequency("P9_22", fad)
    time.sleep(0.6)
    PWM.set_frequency("P9_22", mi)
    time.sleep(0.45)
    PWM.set_frequency("P9_22", si)
    time.sleep(0.15)
    jouer_note(sol,50)
    jouer_note(sol,50)
    PWM.set_duty_cycle("P9_22", 0)
コード例 #23
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("P9_14", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("P9_14", "11")
         PWM.cleanup()
コード例 #24
0
 def test_pwm_frequency_invalid_value_string(self):
     PWM.start("P9_14", 0)
     with pytest.raises(TypeError):
         PWM.set_frequency("P9_14", "11")
         PWM.cleanup()
コード例 #25
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_15", 100)
         PWM.cleanup()                            
コード例 #26
0
 def set_frequency(self, frequency):
     if not self.mock_hardware:
         PWM.set_frequency(self.pin, frequency)
     else:
         print("%s Setting Frequency to %f" % (self.pin, frequency))
コード例 #27
0
            PWMstarted = 1
            countIDLE = 0
            #open file to append
            file=open(filename,"a")
            #add first column date/time stamp
            file.write(pt)
            #add next columns with raw reading, and converted voltage
            file.write(",%f,%f\n" % (flow,totalflow))
            file.close()
            #if MM/DD/YR changes, update filename
            #this translates to a new file every day
            ##!!!!header row is dropped from subsequent days
            filename = "{0}_{1}_{2}_FIXTURE-flow.csv".format(currentyear, currentmonth, currentday)

        elif stepf >= 60 and PWMstarted == 1:
            PWM.set_frequency(stepperSTEP, stepf)
            countIDLE = 0
            #open file to append
            file=open(filename,"a")
            #add first column date/time stamp
            file.write(pt)
            #add next columns with raw reading, and converted voltage
            file.write(",%f,%f\n" % (flow,totalflow))
            file.close()
            #if MM/DD/YR changes, update filename
            #this translates to a new file every day
            ##!!!!header row is dropped from subsequent days
            filename = "{0}_{1}_{2}_FIXTURE-flow.csv".format(currentyear, currentmonth, currentday)

        elif stepf < 60 and PWMstarted == 1:
            PWM.stop(stepperSTEP)
コード例 #28
0
#!/usr/bin/env python3
# From: https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/pwm
# From: https://adafruit-beaglebone-io-python.readthedocs.io/en/latest/PWM.html

import Adafruit_BBIO.PWM as PWM
LED="P9_14"

# PWM.start(channel, duty, freq=2000, polarity=0)
PWM.start(LED, 50)
 
# Optionally, you can set the frequency as well as the polarity from their defaults:
PWM.start(LED, 50, 1, 1)

# The valid values for duty are 0.0 to 100.0. The start method activate 
# pwm on that channel. There is no need to setup the channels with Adafruit_BBIO.PWM.

# Once you've started, you can then set the duty cycle, or the frequency:
PWM.set_duty_cycle(LED, 25.5)
PWM.set_frequency(LED, 10)

# You'll also want to either disable that specific channel, or cleanup all of them when you're done:
    # PWM.stop(LED)
    # PWM.cleanup()
コード例 #29
0
 def changePWMFreq(self, desiredFreq):
     #This function is used to change the frequency of the pwm signal
     pwm.set_frequency("P9_14", desiredFreq)
コード例 #30
0
ファイル: motorPID.py プロジェクト: jay-j/rollbot
	def setPWMFrequency(self,freq):
		PWM.set_frequency(pin_pwm,freq)
コード例 #31
0
import Adafruit_BBIO.PWM as PWM
myPWM = "P8_13"
PWM.start(myPWM, 0, 1000)

for i in range(0,5):
    V = input("What voltage would you like? ")
    DC = (V/3.365)*100
    
    if DC > 100:
        DC=100
    PWM.set_duty_cycle(myPWM, DC)
    PWM.set_frequency(myPWM, 100)
PWM.stop(myPWM)
PWM.cleanup()

コード例 #32
0
def hymne_joie():
    PWM.set_frequency("P9_22", mi)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", mi)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", fa)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", sol)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", sol)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", fa)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", mi)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", re)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", do)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", do)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", re)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", mi)
    time.sleep(tempo)
    PWM.set_frequency("P9_22", mi)
    time.sleep(0.45)
    PWM.set_frequency("P9_22", re)
    time.sleep(0.3)
    PWM.set_frequency("P9_22", re)
    time.sleep(0.6)
    time.sleep(3)
コード例 #33
0
import Adafruit_BBIO.PWM as PWM

#set polarity to 1 on start:
#PWM.start("P9_14", 50, 2000, 1)

#PWM.start(channel, duty, freq=2000, polarity=0)
#duty values are valid 0 (off) to 100 (on)

PWM.start("P9_14", 50)
PWM.set_duty_cycle("P9_14", 25.5)
PWM.set_frequency("P9_14", 10)

PWM.stop("P9_14")
PWM.cleanup()
コード例 #34
0
signal = signal0 + signal1 + signal2 + signal3 + signal4 + signal5 + signal6 + signal7 + signal8 + signal9 + signal10 + signal11 + signal12 + signal13

GPIO.setup("P9_22", GPIO.OUT)


def lecture_son(signal):
    for i in range(33984 / Fe):
        if signal[i] > 0:
            GPIO.output("P9_22", GPIO.HIGH)
        else:
            GPIO.output("P9_22", GPIO.LOW)
        time.sleep(1 / Fe)


PWM.start("P9_22", 50)
PWM.set_frequency("P9_22", Fe)
tempo = 0.3

do = 523  #261
re = 587  #293
mi = 659  #329
fa = 698  #349
sol = 783  #391
la = 880  #440
si = 987  #493

if __name__ == "__main__":
    while True:
        '''
        PWM.set_frequency("P9_22", mi)
        time.sleep(tempo)
コード例 #35
0
def setSpeed(pin, speed=0.5):
    if pin and 0 <= speed <= 1:
        PWM.set_frequency(pin, 1000 / (1 + speed))
        PWM.set_duty_cycle(pin, 0.7)  #(0.7+speed)/(1+speed))
        print("The speed is setted to %s" % speed)
コード例 #36
0
 def test_pwm_frequency_invalid_value_negative(self):
     PWM.start("P9_14", 0)
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_14", -1)
         PWM.cleanup()
コード例 #37
0
dmx = EnttecUsbDmxProWidget.EnttecUsbDmxProWidget()
dmx.setPort("/dev/ttyO2", 115200)
dmx.connect()
dmx.sendDMX([1,2,3,4])
# Continuously read and print packets
while True:
    rx = dmx.getRecievedFrame()
    ResponseArray = rx['frame']
    print(ResponseArray)
    try:
        if ResponseArray != []:            
            if ((ResponseArray[0] == 1) and ((ResponseArray[1] < .15) and (ResponseArray[1] > -.15))): #Brake
                PWM.start("P9_14", 50, 1000, 1)
                PWM.set_duty_cycle("P9_14", 25.5) #Input A CHANGE ONCE JACK/RYAN GET HERE
                PWM.set_frequency("P9_14", 10) #Frequency A
                PWM.start("P9_15", 50, 1000, 1)
                PWM.set_duty_cycle("P9_15", 25.5) #Input B
                PWM.set_frequency("P9_15", 10) #Frequency B
                sleep(.02)
                PWM.stop("P9_14") #stops for a second
                PWM.stop("P9_15") #stops for a second

            if ((ResponseArray[0] == 1) and (ResponseArray[1] >= .25)): #Reverse
                PWM.start("P9_15", 50, 1000, 1)
                PWM.set_duty_cycle("P9_15", 25.5) #Input B
                PWM.set_frequency("P9_15", 10)
                sleep(.02)
                PWM.stop("P9_14") #stops for a second
                PWM.stop("P9_15") #stops for a second
コード例 #38
0
 def test_pwm_freq_non_setup_key(self):
     with pytest.raises(ValueError):
         PWM.set_frequency("P9_15", 100)
         PWM.cleanup()
コード例 #39
0
#!/usr/bin/env python3
import Adafruit_BBIO.PWM as PWM

#set polarity to 1 on start:
#PWM.start("P9_14", 50, 2000, 1)

#PWM.start(channel, duty, freq=2000, polarity=0)
#duty values are valid 0 (off) to 100 (on)

SERVO="P9_14"
PWM.start(SERVO, 50)
PWM.set_duty_cycle(SERVO, 25.5)
PWM.set_frequency(SERVO, 10)

PWM.stop(SERVO)
PWM.cleanup()
コード例 #40
0
def SetPWM(index, new_dc, new_freq):
    PWM.set_duty_cycle(colors[index], new_dc)
    PWM.set_frequency(colors[index], new_freq)
コード例 #41
0
signal13=A*B*np.array([0]*31620+[1]*1700+[0]*(33984-31620-1700))


signal=signal0+signal1+signal2+signal3+signal4+signal5+signal6+signal7+signal8+signal9+signal10+signal11+signal12+signal13

GPIO.setup("P9_22", GPIO.OUT)
def lecture_son(signal):
    for i in range(33984/Fe):
        if signal[i]>0:
            GPIO.output("P9_22", GPIO.HIGH)
        else:
            GPIO.output("P9_22", GPIO.LOW)
        time.sleep(1/Fe)
        
PWM.start("P9_22", 50)
PWM.set_frequency("P9_22", Fe)
tempo=0.3

do=523#261
re=587#293
mi=659#329
fa=698#349
sol=783#391
la=880#440
si=987#493


if __name__ == "__main__":
    while True:
        '''
        PWM.set_frequency("P9_22", mi)
コード例 #42
0
import time
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
import Adafruit_I2C as I2C
import time


PWM.start("P9_22", 50)
sol=783

if __name__ == "__main__":
   
 
    while True:
        PWM.set_frequency("P9_22", sol)
        lst = range(100, -1, -1)
        for i in lst:
            print(i)
            PWM.set_duty_cycle("P9_22", i)
            time.sleep(0.005)

        
コード例 #43
0
ファイル: StepperMotor.py プロジェクト: ericboehlke/BB-8
 def setSpeed(self, rpm):
     if rpm != 0:
         PWM.set_frequency(self.stepPin, SteppingMode.getFrequency(rpm))
         PWM.set_duty_cycle(self.stepPin, 50)
     else:
         PWM.set_duty_cycle(self.stepPin, 0)
コード例 #44
0
##########################################

try:
    while True:
        GPIO.output(my_led, GPIO.HIGH)
        time.sleep(0.5)
        GPIO.output(my_led, GPIO.LOW)
        time.sleep(0.5)
        print("\nenter new frequency in MHz: ")
        new_value = input()
        new_freq_Hz = 1000
        try:
            new_freq_Hz = int(float(new_value) * 1000 * 1000)
        except ValueError as e:
            print("Exception: ", e)
        print("calculated frequency: \n"
              "{:}MHz (= {:}Hz)"
              "".format(new_freq_Hz / (1000 * 1000), new_freq_Hz))
        PWM.set_frequency(my_pwm, new_freq_Hz)
        PWM.set_duty_cycle(my_pwm, 50)
except KeyboardInterrupt:
    print("exit")
finally:
    print("cleanup")

    GPIO.output(my_led, GPIO.LOW)
    GPIO.cleanup()

    PWM.stop(my_pwm)
    PWM.cleanup()
コード例 #45
0
            countIDLE = 0
            #open file to append
            file = open(filename, "a")
            #add first column date/time stamp
            file.write(pt)
            #add next columns with raw reading, and converted voltage
            file.write(",%f,%f\n" % (flow, totalflow))
            file.close()
            #if MM/DD/YR changes, update filename
            #this translates to a new file every day
            ##!!!!header row is dropped from subsequent days
            filename = "{0}_{1}_{2}_FIXTURE-flow.csv".format(
                currentyear, currentmonth, currentday)

        elif stepf >= 60 and PWMstarted == 1:
            PWM.set_frequency(stepperSTEP, stepf)
            countIDLE = 0
            #open file to append
            file = open(filename, "a")
            #add first column date/time stamp
            file.write(pt)
            #add next columns with raw reading, and converted voltage
            file.write(",%f,%f\n" % (flow, totalflow))
            file.close()
            #if MM/DD/YR changes, update filename
            #this translates to a new file every day
            ##!!!!header row is dropped from subsequent days
            filename = "{0}_{1}_{2}_FIXTURE-flow.csv".format(
                currentyear, currentmonth, currentday)

        elif stepf < 60 and PWMstarted == 1:
コード例 #46
0
	def marche_imperiale(self,pin):
		self.jouer_note(sol, 50)
		self.jouer_note(sol, 50)
		self.jouer_note(sol, 50)
		
		PWM.set_frequency(pin, mi)
		time.sleep(0.45)
		PWM.set_frequency(pin, si)
		time.sleep(0.15)
		PWM.set_frequency(pin, sol)
		time.sleep(0.6)
		PWM.set_frequency(pin, mi)
		time.sleep(0.45)
		PWM.set_frequency(pin, si)
		time.sleep(0.15)
		PWM.set_frequency(pin, sol)
		time.sleep(0.45)
		
		PWM.set_duty_cycle(pin, 0)
		time.sleep(0.6)
		self.jouer_note(re,50)
		self.jouer_note(re,50)
		self.jouer_note(re,50)
		PWM.set_frequency(pin, mi)
		time.sleep(0.45)
		PWM.set_frequency(pin, si)
		
		time.sleep(0.15)
		PWM.set_frequency(pin, fad)
		time.sleep(0.6)
		PWM.set_frequency(pin, mi)
		time.sleep(0.45)
		PWM.set_frequency(pin, si)
		time.sleep(0.15)
		self.jouer_note(sol,50)
		self.jouer_note(sol,50)
		PWM.set_duty_cycle(pin, 0)
コード例 #47
0
dmx.connect()
dmx.sendDMX([1, 2, 3, 4])
# Continuously read and print packets
while True:
    rx = dmx.getRecievedFrame()
    ResponseArray = rx['frame']
    print(ResponseArray)
    try:
        if ResponseArray != []:
            if ((ResponseArray[0] == 1)
                    and ((ResponseArray[1] < .15) and
                         (ResponseArray[1] > -.15))):  #Brake
                PWM.start("P9_14", 50, 1000, 1)
                PWM.set_duty_cycle(
                    "P9_14", 25.5)  #Input A CHANGE ONCE JACK/RYAN GET HERE
                PWM.set_frequency("P9_14", 10)  #Frequency A
                PWM.start("P9_15", 50, 1000, 1)
                PWM.set_duty_cycle("P9_15", 25.5)  #Input B
                PWM.set_frequency("P9_15", 10)  #Frequency B
                sleep(.02)
                PWM.stop("P9_14")  #stops for a second
                PWM.stop("P9_15")  #stops for a second

            if ((ResponseArray[0] == 1)
                    and (ResponseArray[1] >= .25)):  #Reverse
                PWM.start("P9_15", 50, 1000, 1)
                PWM.set_duty_cycle("P9_15", 25.5)  #Input B
                PWM.set_frequency("P9_15", 10)
                sleep(.02)
                PWM.stop("P9_14")  #stops for a second
                PWM.stop("P9_15")  #stops for a second
コード例 #48
0
ファイル: sensor.py プロジェクト: BDR16/svn-migration-dump
 def set(self, duty, freq=1000):
     PWM.set_duty_cycle(self.pin, duty)
     PWM.set_frequency(self.pin, freq)
コード例 #49
0
adc_values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

i2c_values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

i2c = Adafruit_I2C(9)  #communication with Teensy at address 9

#Motor DIR
GPIO.setup("P8_26", GPIO.OUT)
GPIO.setup("P8_14", GPIO.OUT)
GPIO.setup("P8_15", GPIO.OUT)
GPIO.setup("P8_16", GPIO.OUT)
GPIO.setup("P8_17", GPIO.OUT)
#Motor PWM
PWM.start("P9_31", 0.0)
PWM.set_frequency("P9_31", 1000.0)
PWM.start("P9_14", 0.0)
PWM.set_frequency("P9_14", 1000.0)
PWM.start("P8_19", 0.0)
PWM.set_frequency("P8_19", 1000.0)
PWM.start("P9_42", 0.0)
PWM.set_frequency("P9_42", 1000.0)
PWM.start("P9_28", 0.0)
PWM.set_frequency("P9_28", 1000.0)

print "Handexos started"

while True:

    #######################################################################
    #######################################################################
コード例 #50
0
ファイル: newsine.py プロジェクト: priyanshus1/BBB_DAC
omega = 2*pi*freq
sampleRate = 133333.333333
samples = int(sampleRate/freq)
pwms = [0 for _ in range(2000)]
for i in range(2000):
        pwms[i]=0
#pwms[0] = (samples+1)*4
#print pwms[0]
PWM.start("P9_14",50)
for i in range(1,samples+1):
        if i < 2000:
                pwms[i] = 50+int(50*sin(omega*(i-1)/sampleRate))

print "Frequency="+str(freq)+"\n" 
freq=float(raw_input())
PWM.set_frequency("P9_14",freq)
if freq < 67: 
        print "Frequency: "+str(freq)+" is too low. Enter a number higher than 67\n"
        freq = 67
print "Frequency="+str(freq)+"\n"
      
while True:
        if freq >=67:
                omega = 2*pi*freq;
                samples = int(sampleRate/freq);
                #pwms[0] = (samples+1)*4;
                for i in range (1,samples+1):
                        if(i < 2000):
                                pwms[i] = 50+int(50*sin(omega*(i-1)/sampleRate));
                                print pwms[i]
                                PWM.set_duty_cycle("P9_14",pwms[i])
コード例 #51
0
    jouer_note(re,50)
    PWM.set_frequency("P9_22", mi)
    time.sleep(0.45)
    PWM.set_frequency("P9_22", si)
    
    time.sleep(0.15)
    PWM.set_frequency("P9_22", fad)
    time.sleep(0.6)
    PWM.set_frequency("P9_22", mi)
    time.sleep(0.45)
    PWM.set_frequency("P9_22", si)
    time.sleep(0.15)
    jouer_note(sol,50)
    jouer_note(sol,50)
    PWM.set_duty_cycle("P9_22", 0)
    
    
    
    
    
PWM.start("P9_22", 50)
PWM.set_frequency("P9_22", Fe)


if __name__ == "__main__":
    while True:
        #hymne_joie()
        marche_imperiale()
        time.sleep(1)