コード例 #1
0
def loop():
    while True:
        signal = int(ADC.read(0)) * 4
        if signal > Treshold:
            print signal
        ADC.write(ADC.read(0))
        sleep(0.01)
コード例 #2
0
def loop():
    status = 1
    while True:
        print('Value:', ADC.read(0))
        Value = ADC.read(0)
        outvalue = map(Value, 0, 255, 120, 255)
        ADC.write(outvalue)
        time.sleep(0.2)
コード例 #3
0
ファイル: RGBbar.py プロジェクト: cavonlee/RGBbar
def destroy():
    ADC.write(0)
    Rpwm.stop
    Gpwm.stop
    Bpwm.stop
    GPIO.output(Rpin, GPIO.HIGH)
    GPIO.output(Gpin, GPIO.HIGH)
    GPIO.output(Bpin, GPIO.HIGH)
    GPIO.cleanup
コード例 #4
0
ファイル: RGBbar.py プロジェクト: HandcraftCavon/RGBbar
def destroy():
	ADC.write(0)
	Rpwm.stop
	Gpwm.stop
	Bpwm.stop
	GPIO.output(Rpin, GPIO.HIGH)
	GPIO.output(Gpin, GPIO.HIGH)
	GPIO.output(Bpin, GPIO.HIGH)
	GPIO.cleanup
コード例 #5
0
def measure():
    ADC.setup(0x48)
    bus = smbus.SMBus(1)
    reading = ADC.read(2)
    ADC.write(ADC.read(0))
    value = ((0.641025641) * reading)
    moistureLevel = (100 - value) * 2
    if moistureLevel > 100:
        moistureLevel = 100
    return moistureLevel
コード例 #6
0
def loop():
    while True:
        value = ADC.read(0)  # read the potentiometer value
        dc = value / 2.55  # duty cycle goes from 0 to 100, the potentiometer value from 0 to 255
        print 'Value: ' + str(value)
        print 'DC: ' + str(dc)
        p.ChangeDutyCycle(
            dc)  # set the brightness, changing duty cycle to the value of dc
        ADC.write(value)
        time.sleep(0.05)  # wait for 50 ms
コード例 #7
0
def loop():
    while True:
        value = ADC.read(0)  # read the potentiometer value
        ms = float(value) / 1000
        print 'Milliseconds: ' + str(ms)
        ADC.write(ms)
        print "Led ON..."
        GPIO.output(ledPin, GPIO.LOW)  # turn on led
        time.sleep(ms)  # wait for the number of seconds in ms
        print "Led OFF..."
        GPIO.output(ledPin, GPIO.HIGH)  # turn off led
        time.sleep(ms)  # wait for the number of seconds in ms
コード例 #8
0
def loop():
    while True:
        for pin in pins:  # turn on LEDs from left to right
            value = ADC.read(0)  # read the potentiometer value
            ms = float(value) / 1000
            ADC.write(ms)
            GPIO.output(pin, GPIO.LOW)  # turn on the LED
            time.sleep(ms)  # wait for the number of seconds in ms
        for pin in invertedPins:  # turn off LEDs from right to left
            value = ADC.read(0)  # read the potentiometer value
            ms = float(value) / 1000
            ADC.write(ms)
            GPIO.output(pin, GPIO.HIGH)  # turn off the LED
            time.sleep(ms)  # wait for the number of seconds in ms
        for pin in invertedPins:  # turn on LEDs from right to left
            value = ADC.read(0)  # read the potentiometer value
            ms = float(value) / 1000
            ADC.write(ms)
            GPIO.output(pin, GPIO.LOW)  # turn on the LED
            time.sleep(ms)  # wait for the number of seconds in ms
        for pin in pins:  # turn off LEDs from left to right
            value = ADC.read(0)  # read the potentiometer value
            ms = float(value) / 1000
            ADC.write(ms)
            GPIO.output(pin, GPIO.HIGH)  # turn off the LED
            time.sleep(ms)  # wait for the number of seconds in ms
コード例 #9
0
def indexroute():
    Temp_units = ADC.read(0)  #Read ADC units on chn 0
    Temp_volts = (
        Temp_units * 3.3
    ) / 256  #Convert to voltage based on ADC resolution (vref+-vref-)/2^N
    temp = Temp_volts / 0.01  # using temperature sensor eqn: 10mV/1C
    ADC.write(Temp_units)  # write to dac to adjust LED brightness
    Hum_units = ADC.read(1)  #Read ADC units on chn 1
    Hum_volts = (
        Hum_units * 3.3
    ) / 256  #Convert to voltage based on ADC resolution (vref+-vref-)/2^N
    humidity = (Hum_volts - 0.985) / 0.0307  # using humidity sensor eqn
    return "Welcome! The current temp is %2.2f and the humidity is %2.2f" % (
        temp, humidity)  #Return the temp and humidty
コード例 #10
0
ファイル: GardenBot.py プロジェクト: jenanos/GardenBot
def loop():
    status = 1
    while True:
        print('Value:', ADC.read(0))
        Value = ADC.read(0)
        if Value > 250:
            ##                if ADC.read(0) < 120:
            print('...relayd on')
            GPIO.output(RelayPin, GPIO.LOW)
        else:
            print('relay off...')
            GPIO.output(RelayPin, GPIO.HIGH)
        outvalue = map(Value, 0, 255, 120, 255)
        ADC.write(outvalue)
        time.sleep(0.2)
コード例 #11
0
ファイル: vu_meter.py プロジェクト: k3xx/vumeter
def main():
    try:
        ADC.setup(0x48)  # Set up the GPIO pins used to talk to the DAC
        monitor = PeakMonitor(SINK_NAME, METER_RATE)

        for sample in monitor:
            # samples range from 0 to 127 so double them to get the full voltage
            # range of the DAC ("<< 1")
            #            sample = sample << 1
            sample = sample * 1.42  # reduce range for better VU scale
            #            sample = table[sample] # ...using loopup table

            #            print sample
            ADC.write(sample)

    except KeyboardInterrupt:  #Ctrl+C pressed
        print
        print "Shutdown requested...exiting"

    monitor.flushqueue()
コード例 #12
0
def destroy():
    ADC.write(0)
コード例 #13
0
def destroy():
    p.stop()  # stop the PWM instance
    ADC.write(0)
    GPIO.output(ledPin, GPIO.HIGH)  # turn off led
    GPIO.cleanup()  # release resource
コード例 #14
0
def menu():
    global direction
    global submenu
    global main_menu
    global DAC0_status

    if direction == "up":
        submenu = submenu - 1
    elif direction == 'down':
        submenu = submenu + 1
    elif direction == "right":
        main_menu = main_menu + 1
        submenu = 1
    elif direction == "left":
        main_menu = main_menu - 1
        submenu = 1

    if main_menu == 12:
        main_menu = 1
    if main_menu == 0:
        main_menu = 11

    temp, pressure = bmp.get_temperature_and_pressure()  #BMP280 code line

    #Information
    if main_menu == 1:
        Temp_C, Temp_F = RTC.getTemp()  #ds3231 code line

        if submenu == 4:
            submenu = 1
        if submenu == 0:
            submenu = 3

        if submenu == 1:
            oled("<  1.Time   >", time.strftime('%X'))
        if submenu == 2:
            oled("<  1.Date   >", time.strftime('%x'))
        elif submenu == 3:
            oled("<  1.RTC Temp >", (str(round(Temp_C, 2)) + " C"),
                 (str(round(Temp_F, 2)) + " F"))

    # Sensor data
    elif main_menu == 2:

        if submenu == 3:
            submenu = 1
        if submenu == 0:
            submenu = 2

        if submenu == 1:
            oled("< 2. BMP280 >", "Temperature", (str(round(temp, 2)) + " C"))
        elif submenu == 2:
            oled("< 2. BMP280 >", "Pressure", round(pressure, 2))

    # Device info
    elif main_menu == 3:

        if submenu == 5:
            submenu = 1
        if submenu == 0:
            submenu = 4

        if submenu == 1:
            oled("< 3.Rpi Info >", "CPU Temperature=",
                 (add_module.getCPUtemperature() + " C"))
        elif submenu == 2:
            oled("< 3.Rpi Info >", "Free RAM",
                 (str(int(add_module.getRAMinfo()[2]) / 1024) + " MB"))
        elif submenu == 3:
            oled("< 3.Rpi Info >", "CPU Usage",
                 (str(add_module.getCPUuse()) + " %"))
        elif submenu == 4:
            oled("< 3.Rpi Info >", "Disk Usage", add_module.getDiskSpace()[3])
    # IP Address
    elif main_menu == 4:

        if submenu == 3:
            submenu = 1
        if submenu == 0:
            submenu = 2

        if submenu == 1:
            oled("< 4. Rpi IP's >", "WLAN0",
                 add_module.get_ip_address('wlan0'))
        elif submenu == 2:
            oled("< 4. Rpi IP's >", "ETH0", add_module.get_ip_address('eth0'))

    #Finance
    elif main_menu == 5:

        if submenu == 3:
            submenu = 1
        if submenu == 0:
            submenu = 2

        if submenu == 1:
            oled("< 5. Exch Rate >", "Dolar / TL",
                 DovizKurlari().DegerSor("USD", 4))
        elif submenu == 2:
            oled("< 5. Exch Rate >", "Euro / TL",
                 DovizKurlari().DegerSor("EUR", 4))

    #DAC0, LED1, and ADC0 through ADC3
    elif main_menu == 6:

        if submenu == 6:
            submenu = 1
        if submenu == 0:
            submenu = 5

        if submenu == 1:
            oled("< 6. DAC0/LED1 >", "Turn On/OFF", "Press Button")
            if GPIO.input(KEY) == 0:
                if DAC0_status == 0:
                    GPIO.output(
                        LED1, GPIO.HIGH)  #Turns on LED1 to indicate DAC0 is on
                    ADC.write(255)  #Turns on DAC0
                    DAC0_status = 1
                    time.sleep(.25)
                else:
                    GPIO.output(
                        LED1,
                        GPIO.LOW)  #Turns off LED1 to indicate DAC0 is off
                    ADC.write(0)  #Turns off DAC0
                    DAC0_status = 0
                    time.sleep(.25)

        elif submenu == 2:
            oled("< 6. DAC0/LED1 >", "Ain0",
                 (str(round(ADC.read(0), 2)) + " Volts"))  #PCF8591 code line

        elif submenu == 3:
            oled("< 6. DAC0/LED1 >", "Ain1",
                 (str(round(ADC.read(1), 2)) + " Volts"))  #PCF8591 code line

        elif submenu == 4:
            oled("< 6. DAC0/LED1 >", "Ain2",
                 (str(round(ADC.read(2), 2)) + " Volts"))  #PCF8591 code line

        elif submenu == 5:
            oled("< 6. DAC0/LED1 >", "Ain3",
                 (str(round(ADC.read(3), 2)) + " Volts"))  #PCF8591 code line

    #System
    elif main_menu == 7:

        if submenu == 5:
            submenu = 1
        if submenu == 0:
            submenu = 4

        elif submenu == 1:
            oled("< 7. System >", "Close App", "Press Button")
            if GPIO.input(KEY) == 0:
                sys.exit()
        elif submenu == 2:
            oled("< 7. System >", "Restart", "Press Button")
            if GPIO.input(KEY) == 0:
                os.popen('sudo reboot')
        elif submenu == 3:
            oled("< 7. System >", "Halt System", "Press Button")
            if GPIO.input(KEY) == 0:
                os.popen('sudo halt')
        elif submenu == 4:
            oled("< 7. System >", "App Update", "Press Button")
            if GPIO.input(KEY) == 0:
                oled("< 7. System >", "Update ...")
                os.popen('sudo apt-get update')
                oled("< 7. System >", "Upgrade ...")
                os.popen('sudo apt-get upgrade -y')
                oled("< 7. System >", "Completed")

    #Additional sensors
    elif main_menu == 8:
        temp_c, temp_f = OneWire.read_temp()  #ds18b20 code line
        f = OneWire.read_rom()  #ds18b20 code line

        if submenu == 3:
            submenu = 1
        if submenu == 0:
            submenu = 2

        if submenu == 1:
            oled("< 8. Sensors >", f, (str(round(temp_c, 2)) + " C"))
        elif submenu == 2:
            oled("< 8. Sensors >", f, (str(round(temp_f, 2)) + " F"))

    # IRM readings
    elif main_menu == 9:

        if submenu == 2:
            submenu = 1
        if submenu == 0:
            submenu = 1

        if submenu == 1:
            IRM_key = IRM.irm_key()
            oled("< 9. IRM >", "Readings",
                 IRM_key)  #This is not catching all the button presses.
            #The issue is the structure of this program would need to change to handle the timing.
            #Running a thread does not improve program response to sensor input. To improve the
            #response to the sensor input the program needs to be restructured/shortened.

    #USB2UART TX Test
    elif main_menu == 10:
        oled("< 10. USB2UART >", "Run TX test", "Press Button"
             )  #This is to test the transmission from the Pi to a PC.
        if GPIO.input(KEY) == 0:
            ser.write("Test line\r\n".encode())
            oled("< 10. USB2UART >", "Test line sent", "View results")
            time.sleep(2)

    #USB2UART RX Test
    elif main_menu == 11:
        oled("< 11. USB2UART >", "Run RX test",
             "Press Button")  #This is to test the
        #transmission from the PC to a Pi. No more than a small word, due to the OLED size.
        if GPIO.input(KEY) == 0:
            flush_input()  #Calls the function to clear the
            #terminal keyboard buffer before the desired input is collected.
            oled("< 11. USB2UART >", "Button Pressed", "Starting test")
            ser.write("Type something\r\n".encode())
            out = USB2UART.readData()
            oled("< 11. USB2UART >", "You wrote:", str(out))
            ser.write("You wrote: ".encode() + str(out).encode() +
                      "\r\n".encode())
            time.sleep(2)

    else:
        print("something went wrong")

    return (submenu)
コード例 #15
0
ファイル: main.py プロジェクト: hscasn/junkyard
def destroy():
    GPIO.cleanup()
    ADC.write(0)
コード例 #16
0
def destroy():
    con.close()
    ADC.write(0)
コード例 #17
0
ファイル: Smirror.py プロジェクト: MostafaAbuelnoor/Smirror
        if apass != kpass:
            print "Invalid Password\n"
else:
    while validate_rfid(data) != rfidpass:
        data = ser.read(12)
        print "Invalid RFID Tag\n"

song1()
mycam.start_preview()
print "\nWelcome to SMirror\n Flip switch 1 to take a picture, 4 to take a video and 8 to start the server"
try:
    while True:
        (tp, tpunits) = temp(2)
        (otp, otpunits) = temp(1)
        (lint, lintunits) = light(3)
        adc.write(lintunits)
        tp = float(tp)
        otp = float(otp)
        otp = otp / 5.00
        time.sleep(0.5)
        if tp >= 23:
            lcd.clear()
            gpio.output(ledac, 1)
            lcd.write(0, 0, "AC is ON")
            lcd.write(0, 1, "Room Temp: %2.2fC" % tp)
        else:
            lcd.clear()
            gpio.output(ledac, 0)
            lcd.write(0, 0, "AC is OFF")
            lcd.write(0, 1, "Room Temp: %2.2fC" % tp)
コード例 #18
0
def loop():
	while True:
		print ADC.read(0)
		ADC.write(ADC.read(0))
コード例 #19
0
ファイル: vibrate.py プロジェクト: mdtconv/HeartBeatClient
import PCF8591 as ADC
import time

ADC.setup(0x48)
while True:
    ADC.write(0)
    time.sleep(0.1)
コード例 #20
0
def destroy():
    ADC.write(0)
    GPIO.output(ledPin, GPIO.HIGH)  # turn off led
    GPIO.cleanup()  # release resource
コード例 #21
0
def vibrate():
    ADC.setup(0x48)
    ADC.write(255)
    time.sleep(0.3)
    ADC.write(0)
    print "vibrate!"
コード例 #22
0
def loop():
    while True:
        print(ADC.read(0))
        ADC.write(ADC.read(0))
コード例 #23
0
 def ADWrite(self, value):
     ADC.write(value)
コード例 #24
0
ファイル: soundsensor.py プロジェクト: refap3/refAP3repo
def destroy():
    ADC.write(0)
import PCF8591 as ADC
ADC.setup(0x48)
trt:
    while True:
        print(ADC.read(0))
        ADC.write(ADC.read(0))
finally:
    ADC.write(0)