def __init__(self, cube): CLEAR = 0 BLUE = 1 GREEN = 2 CYAN = 3 RED = 4 MAGENTA = 5 YELLOW = 6 WHITE = 7 self.rgb_led = [RGBLED(4), RGBLED(5)] self.led = [LED(3), LED(2), LED(1), LED(0)] self.button = [Button(index) for index in range(4)] self.switch = [Switch(0), Switch(1)] self.colors = { "D": WHITE, "F": GREEN, "U": YELLOW, "L": RED, "R": MAGENTA, "B": BLUE } self.faces = {"D": 5, "F": 0, "U": 4, "L": 3, "R": 1, "B": 2} self.speed = 3 self.cube = cube self.address_ports = [ Arduino_IO(3, i, 'out') for i in reversed(range(6)) ] self.address_clock = Arduino_IO(3, 6, 'out') self.color_clock = Arduino_IO(3, 7, 'out')
def test_leds_on(): """Test for the LED class and its wrapper functions. Instantiates a LED object on index 0 and performs some actions on it to test LED's API, requesting user confirmation. """ leds = [LED(index) for index in range(4)] for led in leds: led.off() led = leds[0] led.on() assert led.read() == 1 assert user_answer_yes("\nOnboard LED 0 on?") led.off() assert led.read() == 0 assert user_answer_yes("Onboard LED 0 off?") led.toggle() assert led.read() == 1 led.write(0) assert led.read() == 0 led.write(1) assert led.read() == 1 led.off()
def test_leds_toggle(): """Test for the LED class and its wrapper functions. Instantiates 4 LED objects and toggles them. """ leds = [LED(index) for index in range(4)] print("\nToggling onboard LEDs. Press enter to stop toggling...", end='') for i in range(4): leds[i].write(i % 2) while True: for led in leds: led.toggle() sleep(0.1) if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: termios.tcflush(sys.stdin, termios.TCIOFLUSH) break for led in leds: led.off() assert user_answer_yes("LEDs toggling during the test?")
from time import sleep from pynq import PL from pynq.board import RGBLED, LED # Wait for PL server to come up timeout = 3 for i in range(timeout): try: PL.ip_dict except: sleep(1) rgbleds = [RGBLED(i) for i in range(4, 6)] leds = [LED(i) for i in range(4)] # Toggle board LEDs leaving small LEDs lit for i in range(8): [l.off() for l in leds] [rgbled.off() for rgbled in rgbleds] sleep(.2) [l.on() for l in leds] [rgbled.on(1) for rgbled in rgbleds] sleep(.2) [rgbled.off() for rgbled in rgbleds]
rosso.write(x) #inizializzazione LED funzled(0) #generazione liste valorifreq = [] distRR = [] valoriGSR = [] #inizializzazione sensore EarClip sul PMOD 2 (JC) e grove id 4 (GR4) earHR = Grove_EarHR(2, 4) # inizializzazione del Led della Zybo led = LED(0) led.off() # lettura valori iniziali battito cardiaco beats, deltaT = earHR.read_raw() oldBeats = beats #definizione e posizionamento ADC sul PMOD 1(JB) e grove id 4(GR4) grove_adc = Grove_ADC(1, 4) delta = 60 start = time.time() end = start while (end - start < delta): valoriGSR.append(grove_adc.read())
frame_in_w = 640 frame_in_h = 480 # ### Step 2: Initialize camera from OpenCV # In[4]: from pynq.drivers.video import Frame import cv2 from time import sleep from pynq.board import LED from pynq.board import RGBLED from pynq.board import Button from pynq.board import Switch leds = [LED(index) for index in range(4)] rgbleds = [RGBLED(index) for index in [4, 5]] btns = [Button(index) for index in range(4)] switches = [Switch(index) for index in range(2)] while (1): x = 0 for btn in btns: if (btn.read() == 1): leds[0].on() videoIn = cv2.VideoCapture(0) print("Image captured!") x = 1 break if (x == 1): break
for i in range (indice-1, max(indice-12, 0), -1): acc += Stringa[i] count +=1 media=acc/count return media # ADC configuration pmod_adc = PMOD_ADC(1) i=0 players = [] sample_freq = 0 # Leds&Button assignements button = Button(0) led1 = LED(0) led2 = LED(1) # We have 2 players -- i<2 while (i<2): # Status Led: Ready to start if(i==0): led1.on() else: led2.on() # Wait button push while(button.read() == 0): time.sleep(0.1)
import constants import OBD import time import shutil import sys import logging import requests from pynq.board import Button from pynq.board import LED LED_POSTING = LED(3) LED_RUNNING = LED(0) LED_2 = LED(2) LED_1 = LED(1) CANSPEED_125 = 7 CANSPEED_250 = 3 CANSPEED_500 = 1 SERVER_URL = 'https://scurvy-can-bus.herokuapp.com/logs' # SERVER_URL = 'http://192.168.1.82:8080/logs' STOP_COUNT = 20 LOG_FILE = "ecu.log" logger = logging.getLogger(__name__) # File logging fileHandler = logging.FileHandler(LOG_FILE) fileHandler.setLevel(logging.INFO)
def monitor(): """Monitor a blackjack game.""" ranks = [2, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 1, 1] classifiers = [ cv2.CascadeClassifier("classifiers/2.xml"), cv2.CascadeClassifier("classifiers/3.xml"), cv2.CascadeClassifier("classifiers/4.xml"), cv2.CascadeClassifier("classifiers/5.xml"), cv2.CascadeClassifier("classifiers/6.xml"), # Some errors. cv2.CascadeClassifier("classifiers/7l.xml"), cv2.CascadeClassifier("classifiers/7r.xml"), cv2.CascadeClassifier("classifiers/8.xml"), cv2.CascadeClassifier("classifiers/9.xml"), # Some errors. cv2.CascadeClassifier("classifiers/10.xml"), cv2.CascadeClassifier("classifiers/face.xml"), cv2.CascadeClassifier("classifiers/a.xml"), # Some errors. cv2.CascadeClassifier("classifiers/as.xml") ] # Some errors. chip_classifier = cv2.CascadeClassifier("classifiers/chip.xml") def process(img, upper, lower): """Detect cards and chips.""" image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) detects = [] for index in range(len(ranks)): try: detects.append(classifiers[index].detectMultiScale( gray, scaleFactor=1.05, minNeighbors=4, maxSize=upper, minSize=lower)) except: detects.append([]) circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 2.5, 25, minRadius=20, maxRadius=30) widths = [] heights = [] out = [[], 0] index = 0 windows = [] for found in detects[:-2]: out[0] += [ranks[index]] * len(detects[index]) index += 1 for (x, y, w, h) in found: widths.append(w) heights.append(h) windows.append((x, y, w, h)) cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 5) for found in detects[-2:]: for (x, y, w, h) in found: if any([ x + w / 2.0 >= xx and x + w / 2.0 <= xx + ww and y + h / 2.0 >= yy and y + h / 2.0 <= yy + hh for (xx, yy, ww, hh) in windows ]): continue out[0] += [1] widths.append(w) heights.append(h) cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 5) if circles is not None: circles = np.round(circles[0, :]).astype("int") for (x, y, r) in circles: if any([ x >= xx and x <= xx + ww and y >= yy and y <= yy + hh for (xx, yy, ww, hh) in windows ]): continue cv2.circle(image, (x, y), r, (255, 0, 255), 4) out[1] += 1 if widths and heights: upper = (max(widths) + 10, max(heights) + 6) lower = (min(widths) - 10, min(heights) - 6) plot.imshow(image) plot.show() print("CURRENT:", out[0], out[1]) return out[0], out[1], upper, lower def update(): """Clear all history and update number of decks.""" state = 2 * switches[1].read() + switches[0].read() [leds[led].write(led <= state) for led in range(len(leds))] return CounterAttack(DECK_MAP[state], THRESH) error_messages = ("[OK]", "[HANDLING FAILED]", "[ATTEMPTING TO HANDLE]", "", "[HANDLED]") exit, reset, new_player, shuffle = (Button(button) for button in range(4)) leds = [LED(led) if led < 4 else RGBLED(led) for led in range(6)] switches = [Switch(0), Switch(1)] counter = update() upper, lower = (150, 90), (50, 30) error = 0 while not exit.read(): try: if reset.read(): counter = update() elif new_player.read(): counter.new_player() elif shuffle.read(): counter.shuffle() success = False cam = cv2.VideoCapture(0) while not success: success, img = cam.read() cam.release() detected, chips, upper, lower = process(img, upper, lower) colors = counter.count(detected, chips) leds[4].write(colors[0]) leds[5].write(colors[1]) if error: error = 0 print(error_messages[error]) except ShuffleError: if error: error = 1 else: error = 4 print("SHUFFLE REQUIRED.", error_messages[error]) except Exception as exception: if error: error = 1 else: error = 2 print(exception, error_messages[error]) finally: if error: [led.off() for led in leds[:5]] wait = 0 # Toggle RGBs blue and relevant button LEDs while not any( button.read() for button in (exit, reset, None, shuffle)[:error] if button): # TODO: Length. if not wait % error: [led.write(not led.read()) for led in leds[4:6]] [ leds[led].toggle() for led in range(error) if led != 2 ]
verde.write(x) giallo.write(x) rosso.write(x) #inizializzazione LED funzled(0) #generazione liste valorifreq=[] distRR=[] valoriGSR=[] #inizializzazione sensore EarClip sul PMOD 2 (JC) e grove id 4 (GR4) earHR = Grove_EarHR(2, 4) # inizializzazione del Led della Zybo led = LED(0) led.off() # lettura valori iniziali battito cardiaco beats, deltaT = earHR.read_raw() oldBeats = beats #definizione e posizionamento ADC sul PMOD 1(JB) e grove id 4(GR4) grove_adc = Grove_ADC(1, 4) delta = 60 start = time.time() end = start while(end - start < delta): valoriGSR.append(grove_adc.read())
def __init__(self): cam = projCam() for i in range(MAX_LEDS): leds[i] = LED(i) for i in range(MAX_BUTTONS): buttons[i] = Button(i)