def set_up_gpio(): GPIO.setmode(GPIO.BOARD) # SETUP NUMBERING SYSTEM FOR GPIO GPIO.setwarnings(False) # DISABLE WARNINGS # SETTING UP INPUT/OUTPUT PINS ******************************************* #GPIO.setup(__SWITCH_PIN__, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #SWITCH - IN GPIO.setup(__MOTION_PIN__, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #MOTION SENSOR - PIR - IN GPIO.setup(__SOUND_PIN__, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #SOUND SENSOR - IN GPIO.Setup(chan_list2,(GPIO.OUT,GPIO.OUT,GPIO.OUT)) #RED/GREEN LED OUT & BUZZER OUT ''' GPIO.setup(__RED_LED_PIN__, GPIO.OUT) GPIO.setup(__GREEN_LED_PIN__, GPIO.OUT) GPIO.setup(__BUZZER_PIN__, GPIO.OUT) ''' GPIO.output(chan_list2,(GPIO.LOW,GPIO.LOW,GPIO.HIGH)) #RED/GREEN LED OFF - BUZZER OFF
import cv2 import numpy as np import RPi.GPIO as GPIO red = 8 yellow = 9 GPIO.setup(GPIO.BOARD) GPIO.Setup(red, GPIO.OUT,initial=0) GPIO.Setup(yellow, GPIO.OUT,initial=0) # avvailable digital pins on the pi 4 7 8 9 10 11 14 15 17 18 22 23 24 cap = cv2.VideoCapture(0) lower_red = np.array([160,140,50]) upper_red = np.array([180,255,255]) lower_yellow = np.array([20,100,100]) upper_yellow = np.array([30,255,255]) countRed = 0 countYellow = 0 redFound = False def ballSearch(): while(True): global countRed global countYellow success,frame = cap.read() hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV) hsv = cv2.medianBlur(hsv,5)
#Create variables for our code #Have an ultrasonic sensor light up an led when it reaches a certain distance #Libraries import RPi.GPIO as GPIO import time #GPIO mode (BOARD/BCM) GPIO.setmode(GPIO.BCM) #set GPIO Pins GPIO_TRIGGER = 18 GPIO_ECHO = 24 #set GPIO direction(IN/OUT) GPIO.Setup(GPIO_TRIGGER, GPIO.OUT) GPIO.Setup(GPIO_ECHO, GIO.IN) def distance() #set TRIGGER to high GPIO.output(GPIO_TRIGGER, True) #set Trigger after 0.01ms to low time.sleep(0.00001) GPIO.output(GPIO_TRIGGER, False) StartTime = time.time() StopTime = time.time() #save StartTime while GPIO.input(GPIO_ECHO) == 0: