def right_on(): '''Włączenie prawego światła w sygnalizatorze na przejeździe kolejowym''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 4: city.board.digital[p * 3 + 2].write(1) return 0 p += 1 return p
def red_off(): '''Wyłączenie czerwonego światła''' p = 3 while p >= 0: a = city.read_port(p) x = city.device_detect(a) if x == 6: city.board.digital[p * 3 + 2].write(0) return 0 p -= 1 return p
def green_on(): '''Włączenie zielonego światła''' p = 3 while p >= 0: a = city.read_port(p) x = city.device_detect(a) if x == 6: city.board.digital[p * 3 + 4].write(1) return 0 p -= 1 return p
def yellow_off(): '''Wyłączenie żółtego światła''' p = 3 while p >= 0: a = city.read_port(p) x = city.device_detect(a) if x == 6: city.board.digital[p * 3 + 3].write(0) return 0 p -= 1 return p
def green_off(): '''Wyłączenie światła zielonego''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 5: city.board.digital[p * 3 + 3].write(0) return 0 p += 1 return p
def yellow_on(): '''Włączenie żółtego światła''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 6: city.board.digital[p*3+3].write(1) return 0 p += 1 return p
def left_off(): '''Wyłączenie lewego światła w sygnalizatorze na przejeździe kolejowym''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 4: city.board.digital[p * 3 + 3].write(0) return 0 p += 1 return p
def red_on(): '''Włączenie czerwonego światła''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 6: city.board.digital[p*3+2].write(1) return 0 p += 1 return p
def on_eco(): '''Włączenie lampy w trybie oszczędnościowym (połowa diod)''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 1: city.board.digital[p * 3 + 2].write(1) city.board.digital[p * 3 + 3].write(0) return 0 p += 1 return p
def off(): '''Wyłączenie lampy''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 1: city.board.digital[p * 3 + 2].write(0) city.board.digital[p * 3 + 3].write(0) return 0 p += 1 return p
def green_off(): '''Wyłączenie zielonego światła''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) sleep(0.2) if x == 6: city.board.digital[p*3+4].write(0) return 0 p += 1 return p
def close_right(): '''Zamknięcie zapory w prawo''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 3: city.board.digital[p*3+3].mode = SERVO city.board.digital[p*3+3].write(0) city.isBarrierOpen = False return 0 p += 1 return p
def is_dark(): '''Wykrywanie poziomu natężenia światła w otoczeniu lampy''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 1: if a < 105: # można ustalić inny poziom return True # ciemno else: return False # jasno p += 1 return False # lampa nie jest podłączona do sterownika
def off(): '''Wyłączenie wszystkich świateł''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 6: city.board.digital[p*3+2].write(0) city.board.digital[p*3+3].write(0) city.board.digital[p*3+4].write(0) return 0 p += 1 return p
def open(): '''Podniesienie (otwarcie) zapory kolejowej''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 3: if not(city.isBarrierOpen): city.board.digital[p*3+3].mode = SERVO city.board.digital[p*3+3].write(90) city.isBarrierOpen = True return 0 p += 1 return p
def yellow_blink(count=3): '''Włączenie żółtego pulsującego światła - domyślnie 3 błyski''' p = 3 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 6: for i in range(count): city.board.digital[p * 3 + 3].write(1) sleep(0.5) city.board.digital[p * 3 + 3].write(0) sleep(0.5) return 0 p -= 1 return p
def is_train(): '''Detekcja przejeżdząjącego pociągu - czujnik przejazdu''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 2: city.board.digital[p*3+2].mode = INPUT city.board.digital[p*3+2].enable_reporting() if city.board.digital[p*3+2].read() == 1: return True else: return False p += 1 return False
def green_blink(count=2): '''Włączenie pulsującego światła zielonego - domyślnie 2 s''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 5: for i in range(count * 2): sleep(0.25) city.board.digital[p * 3 + 3].write(0) sleep(0.25) city.board.digital[p * 3 + 3].write(1) city.board.digital[p * 3 + 3].write(0) return 0 p += 1 return p
def beacon(): '''Sygnał ostrzegawczy''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) sleep(0.2) if x == 3: city.board.digital[p*3+2].mode = OUTPUT for i in range(4): city.board.digital[p*3+2].write(1) sleep(0.3) city.board.digital[p*3+2].write(0) sleep(0.1) return 0 p += 1 return p
def is_pressed(): '''Odczytywanie stanu przycisku w sygnalizatorze''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 5: # ustawienie pinu cyfrowego w trybie wejścia - przycisk city.board.digital[p * 3 + 4].mode = INPUT city.board.digital[p * 3 + 4].enable_reporting() # odczyt stanu pinu cyfrowego - stan przycisku button = city.board.digital[p * 3 + 4].read() if button == 1: return True # przycisk naciśnięty else: return False # przycisk zwolniony p += 1 return False # urządzenie nie jest podłączone do sterownika
def blink(count=5): '''Pulsujące naprzemiennie światła w sygnalizatorze na przejeździe kolejowym (domyślnie pięć powtórzeń)''' p = 0 while p < 4: a = city.read_port(p) x = city.device_detect(a) if x == 4: for i in range(count): city.board.digital[p * 3 + 2].write(0) city.board.digital[p * 3 + 3].write(1) sleep(0.5) city.board.digital[p * 3 + 2].write(1) city.board.digital[p * 3 + 3].write(0) sleep(0.5) city.board.digital[p * 3 + 2].write(0) return 0 p += 1 return p