def __init__(self,pins,real_true = GPIO.HIGH): ''' Init the leds :param pin: pin numbers in array :param real_true: GPIO.HIGH or GPIO.LOW :return: void ''' self.__ic_74hc595 = IC_74HC595(pins,real_true) for name,number in pins.items(): GPIO.setup(number,GPIO.OUT)
def setupp(): GPIO.setmode(GPIO.BOARD) # Setup GPIO Pins GPIO.setup(12, GPIO.OUT) GPIO.setup(32, GPIO.OUT) GPIO.setup(33, GPIO.OUT) GPIO.setup(35, GPIO.OUT)
def __init__(self,par_RS,par_RW,par_E,par_DB4,par_DB5,par_DB6,par_DB7): self.__RS = par_RS self.__RW = par_RW self.__E = par_E self.__DB4 = par_DB4 self.__DB5 = par_DB5 self.__DB6 = par_DB6 self.__DB7 = par_DB7 allpins = [self.__RS,self.__RW,self.__E, self.__DB4, self.__DB5, self.__DB6, self.__DB7] GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) for pin in allpins: GPIO.setup(pin, GPIO.OUT) self.__pins = [par_DB7,par_DB6,par_DB5,par_DB4] self.__delay_instructie = 0.005
import RPi._GPIO as GPIO import time GPIO.setmode(GPIO.BCM) ControlPin = [17, 18, 27, 22] for pin in ControlPin: GPIO.setup(pin, GPIO.OUT) GPIO.setup(pin, GPIO.LOW) seq = [[1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 1, 1], [0, 0, 0, 1], [1, 0, 0, 1]] for i in range(512): for halfstep in range(8): for pin in range(4): a = ControlPin[pin], seq[halfstep][pin] GPIO.output(ControlPin[pin], seq[halfstep][pin]) time.sleep(0.001) GPIO.cleanup()
def run(self): GPIO.setup(A0Mux, GPIO.OUT) GPIO.setup(A1Mux, GPIO.OUT) GPIO.setup(muxEnable, GPIO.OUT) GPIO.setup(A0, GPIO.OUT) GPIO.setup(A1, GPIO.OUT) GPIO.setup(A2, GPIO.OUT) GPIO.output(muxEnable, False) thread2.start() time.sleep(2) print("Enable #1") GPIO.output(muxEnable, True) GPIO.output(A0Mux, False) GPIO.output(A1Mux, False) # 000 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #001 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #010 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #011 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #100 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #101 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #110 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(1) #111 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(2) print("Enable #2") GPIO.output(muxEnable, True) GPIO.output(A0Mux, True) GPIO.output(A1Mux, False) # 000 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #001 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #010 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #011 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #100 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #101 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #110 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(1) #111 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(2) print("Enable #3") GPIO.output(muxEnable, True) GPIO.output(A0Mux, False) GPIO.output(A1Mux, True) # 000 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #001 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #010 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #011 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #100 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #101 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #110 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(1) #111 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(2) print("Enable #4") GPIO.output(muxEnable, True) GPIO.output(A0Mux, True) GPIO.output(A1Mux, True) # 000 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #001 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, False) time.sleep(1) #010 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #011 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, False) time.sleep(1) #100 GPIO.output(A0, False) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #101 GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, True) time.sleep(1) #110 GPIO.output(A0, False) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(1) #111 GPIO.output(A0, True) GPIO.output(A1, True) GPIO.output(A2, True) time.sleep(2) GPIO.output(muxEnable, False) print("Test Completed!") q.put(_sentinel)
import socket import sys import signal #Initialisation du Server serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = "172.20.21.164" port = 15554 buffer_size = 256 #Initialisation du Servo-Moteur GPIO.cleanup() servoPIN = 4 GPIO.setmode(GPIO.BCM) GPIO.setup(servoPIN, GPIO.OUT) p = GPIO.PWM(servoPIN, 50) # GPIO PIN for PWM with 50Hz p.start(0) # Initialization # Captation des Signaux def close(signal, frame): #close socket serverSocket.close() #close and clean gpio p.stop() GPIO.cleanup() print 'SIG: ' + str(signal) + ' Program Interupted' sys.exit()
import RPi._GPIO as GPIO import time GPIO.setmode(GPIO.BCM) Output Pis = [17,22,25,26] for items in Outputs: GPIO.setup(items,GPIO.OUT) GPIO.output(items,True) time.sleep(25) GPIO.cleanup()
def GPIO_Initialize (gpio_pin): GPIO.setmode(GPIO.BCM) GPIO.setup(gpio_pin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.add_event_detect(gpio_pin, GPIO.FALLING, callback = GPIO_CallbackFunc, bouncetime = 500) print "Pin " + str(gpio_pin) + " set" return
#!/usr/bin/python #coding: utf-8 import RPi._GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) SW = [7, 8, 10, 11, 12, 13, 15, 16] for i in range(0, 8): GPIO.setup(SW[i], GPIO.IN, pull_up_down=GPIO.PUD_DOWN) def isPushed(ch): key_in = GPIO.input(ch) if key_in == 0: return 1 else: return 0 try: while 1: for i in range(0, 8): print i, print ' : ', print isPushed(SW[i]) time.sleep(0.1) except KeyboardInterrupt: pass GPIO.cleanup()
return RS = 16 RW = 20 E = 21 D4 = 6 D5 = 13 D6 = 19 D7 = 26 GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(12, GPIO.OUT) GPIO.setup(17, GPIO.OUT) class LCD: def __init__(self,par_RS,par_RW,par_E,par_DB4,par_DB5,par_DB6,par_DB7): self.__RS = par_RS self.__RW = par_RW self.__E = par_E self.__DB4 = par_DB4 self.__DB5 = par_DB5
def setup_pins(): GPIO.setmode(GPIO.BCM) # , pull_up_down=GPIO.PUD_DOWN GPIO.setup(power_pin, GPIO.OUT) GPIO.output(power_pin, 1)
def run(self): GPIO.setup(A0Mux, GPIO.OUT) GPIO.setup(A1Mux, GPIO.OUT) GPIO.setup(muxEnable, GPIO.OUT) GPIO.setup(A0, GPIO.OUT) GPIO.setup(A1, GPIO.OUT) GPIO.setup(A2, GPIO.OUT) GPIO.output(muxEnable, False) thread2.start() time.sleep(2) print("Enable #4") GPIO.output(muxEnable, True) GPIO.output(A0Mux, True) GPIO.output(A1Mux, True) time.sleep(1) #101 (Y5) GPIO.output(A0, True) GPIO.output(A1, False) GPIO.output(A2, True) print("Charge On!") q.put(_sentinel)
#all reqd for gui class import tkinter as tk #import GUI library from PIL import Image, ImageTk from tkinter import messagebox import pygame #sound GPIO.setmode(GPIO.BOARD) #use physical pin numbering GPIO.setwarnings(False) #disable warnings chan_list1=[3,11,29,31,32,33] ##Setup for input & output pins #3 Left Flipper Input (EOS Switch In) #5 Right Flipper Input (EOS Switch In) #7 Left Flipper Output (PWM) #8 Right Flipper Output (PWM) #10,11,12,13 Pop Bumpers (Points) GPIO.setup(chan_list1,GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup([7,13],GPIO.OUT) #Set PWM on pins 7 & 8 to 1,000 Hz. Start at 50% PWM pwm1=GPIO.PWM(7, 1000) pwm2=GPIO.PWM(13, 1000) pwm1.start(100) pwm2.start(100) ##input channels for playfield_parts chan_list2=[15,16,18,19,21,22,23] GPIO.setup(chan_list2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #Slingshot 1 Input (Points) #Initialize Sounds pygame.mixer.pre_init(44100, -16, 2, 4096) #frequency, size, channels, buffersize pygame.mixer.init() #turn all of pygame on.
#!/usr/bin/python #coding: utf-8 import RPi._GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) SW = [7, 8, 10, 11, 12, 13, 15, 16] for i in range(0, 8): GPIO.setup(SW[i], GPIO.IN, pull_up_down=GPIO.PUD_DOWN) def isPushed(ch): key_in = GPIO.input(ch) if key_in == 0: return 1 else: return 0 try: while 1: for i in range(0, 8): print i, print ' : ', print isPushed(SW[i]) time.sleep(0.1) except KeyboardInterrupt: pass
# Chuong trinh chop tat led i thoi gian ngan, mo ta pwm import RPi._GPIO as GPIO from time import sleep pin = 14 #khai bao pin out GPIO.setmode(GPIO.BCM) #khai bao kieu pin GPIO.setup(pin, GPIO.OUT) #setup pin output try: while True: GPIO.output(pin, True) #bat led sleep(0.001) #delay 1ms GPIO.output(pin, False) #tat led sleep(0.009) #delay 1ms except KeyboardInterrupt: #thoat chuong trinh khi an Ctrl + C print(" Thoat chuong trinh") GPIO.cleanup()