def prepare(self): """ Prepare environment. """ # Prepare GPIO. GPIO.setmode(GPIO.BCM) for pin in self.pins: if self.pins[pin][1] == 'out': GPIO.setup(self.pins[pin][0], GPIO.OUT) GPIO.output(self.pins[pin][0], GPIO.HIGH) elif self.pins[pin][1] == 'in': GPIO.setup(self.pins[pin][0], GPIO.IN) # Initialize modules. self.oled = Display(port=self.oled_port, address=self.oled_i2c_address) self.oled.images_path = self.images_path self.menu = Menu(rr=self) self.beeper = Beeper(gpio=GPIO, speaker_pin=self.pins['Beeper'][0]) self.beeper.mute = not self.sounds_is_on self.leds = Leds(gpio=GPIO, pins=self.pins) self.usrinfo = UsrInfo(display=self.oled, leds=self.leds) self.sysinfo = SysInfo(display=self.oled, leds=self.leds) # Set interrupts for buttons. for pin in self.pins: if 'BTN_' in pin: GPIO.add_event_detect(self.pins[pin][0], GPIO.FALLING, callback=self.button_pressed, bouncetime=100)
def main(): logger.info('Initialize') data_sink = Observable() builder = Builder(config) builder.bind(data_sink) leds = Leds() while True: try: prices = [entry[1:] for entry in get_dummy_data() ] if config.dummy_data else fetch_prices() data_sink.update_observers(prices) leds.off() time.sleep(config.refresh_interval) except Exception as e: logger.error(str(e)) leds.on() time.sleep(10) except KeyboardInterrupt: logger.info('Exit') data_sink.close() exit()
def __init__(self, config_file, mock_gpio=False): super().__init__() if not mock_gpio: GPIO.setwarnings(False) if GPIO.getmode() != GPIO.BOARD: GPIO.setmode(GPIO.BOARD) Electrical.setup_gpio() Eink.EPD = EPD() self.eink = Eink(reactor) self.config = self._parse_config(config_file) self._setup_logging(self.config) self.app_state = AppState(self.config) self.leds = Leds() self.machine = Machine(reactor, self.app_state, self.eink, self.leds) self.network_health = NetworkHealth(reactor, self.machine) self.invoicer = Invoicer(reactor, self.app_state, self.machine) self.electical = Electrical(reactor, self.machine)
def __init__(self): print(" [*] Application starting") self.status = 'valid' self.config = Config() self.status = self.config.status self.rabbit_client = RabbitMQ_Client(self.config.rabbitmq, self.config.mac, self.config.amqp_encryption_key) self.rabbit_server = RabbitMQ_Server(self.dispatch, self.config.rabbitmq, self.config.mac, self.config.amqp_encryption_key) self.usb_devices = UsbDevices(self.dispatch) self.leds = Leds() self.gpios = Gpios(self.dispatch) self.displays = Displays(self.dispatch) self.rfids = Rfid(self.dispatch) self.lwm2m = Lwm2m(self.config) self.state = State(self.dispatch) self.monitor = Monitor(self.dispatch, self.config)
"8": (65, 2), } # capabilities of the hardware CAPABILITIES = { "channels": 8, "charge": False, "discharge": True, "configurableChargeCurrent": False, "configurableDischargeCurrent": False, "configurableChargeVoltage": False, "configurableDischargeVoltage": True, } # try: status_leds = Leds(number=CAPABILITIES["channels"]) channels = list() current_sensors = CurrentSensors(current_sensor_configuration) wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): log.info("Connecting to WiFi...") wlan.connect("Bill Wi The Science Fi", "225261007622") # wlan.connect("HSBNEWiFi", "HSBNEPortHack") while not wlan.isconnected(): time.sleep(0.25) status_leds.set_channel(4, OFF) status_leds.set_channel(5, BLUE)
from flask import Flask app = Flask(__name__) app.debug = True from leds import Leds from tempsensor import TemperatureSensor from flask import render_template tep = TemperatureSensor() led1 = Leds() led2 = Leds() @app.route('/') def read_temp(): temp_c = tep.WarningTemperature() if temp_c < 22: message = 'froid' led1.led_on('2') led2.led_of('1') elif 22 <= temp_c < 23: message = 'bon' led2.led_of('1') led2.led_of('2') else: message = 'chaud' led1.led_on('1') led2.led_of('2') return render_template('temperature.html', message=message, temp_c=temp_c)
#!/usr/bin/env python3 import time import board import pickle import random from audio import RidderAudio from sensor import Distance from leds import Leds, RGB, WavAnimation, FadeAnimation ## Config from config import * ## Start Script LEDs = Leds(pin=board.D18, num_leds=NumLEDs) sensor = Distance(SensorType) audio = RidderAudio(AudioDir) start = time.time() detect = 0 dice = 0 audioLength = 0 wavAnimation = None def loadAnimation(wav, audioLength): picklefile = wav.replace('.wav', '.pkl') with open(picklefile, 'rb') as f:
from leds import Leds myled = Leds() myled.run(247, 29)
from audio import RidderAudio import time import board from sensor import Distance from leds import Leds print('start') sensor = Distance('vl61') leds = Leds(pin=board.D18, num_leds=4) leds.red() audio = RidderAudio('../audio/') audio.play_random_dankjewel() print('got distance:', sensor.get()) time.sleep(8) audio.play_random_papierhier() time.sleep(8)
def __init__(self, sys_clk_freq, **kwargs): platform = Platform() kwargs["cpu_type"] = None kwargs["with_uart"] = False kwargs["with_timer"] = False #kwargs["with_ctrl"] = False # Force the SRAM size to 0, because we add our own SRAM with SPRAM kwargs["integrated_sram_size"] = 0 kwargs["integrated_rom_size"] = 0 kwargs["csr_data_width"] = 32 clock_ext = [ ("clk16", 0, Pins("20"), IOStandard("LVCMOS33")) ] platform.add_extension(clock_ext) SoCCore.__init__(self, platform, sys_clk_freq, **kwargs) self.submodules.crg = _CRG(platform, sys_clk_freq) reset_btn = platform.request("user_btn_n") self.comb += self.crg.reset.eq(~reset_btn) led = platform.request("user_led_n") led2 = platform.request("user_led_n") spi_ext = [ ("spi_slave", 0, Subsignal("cs_n", Pins("16"), IOStandard("LVCMOS33")), Subsignal("clk", Pins("15"), IOStandard("LVCMOS33")), Subsignal("mosi", Pins("17"), IOStandard("LVCMOS33")), Subsignal("miso", Pins("14"), IOStandard("LVCMOS33")), ), ] platform.add_extension(spi_ext) spi_pads = platform.request("spi_slave") self.submodules.bridge = bridge = SPIBridge(spi_pads) self.bus.add_master(name="bridge", master=self.bridge.wishbone) # UP5K has single port RAM, which is a dedicated 128 kilobyte block. # Use this as CPU RAM. # spram_size = 128 * 1024 # self.submodules.spram = Up5kSPRAM(size=spram_size) # self.register_mem("sram", self.mem_map["sram"], self.spram.bus, spram_size) # The litex SPI module supports memory-mapped reads, as well as a bit-banged mode # for doing writes. # spiflash_size = 16 * 1024 * 1024 # self.submodules.spiflash = SpiFlash(platform.request("spiflash4x"), dummy=6, endianness="little") # self.register_mem("spiflash", self.mem_map["spiflash"], self.spiflash.bus, size=spiflash_size) # self.add_csr("spiflash") # Add ROM linker region #self.add_memory_region("rom", self.mem_map["spiflash"] + flash_offset, spiflash_size - flash_offset, type="cached+linker") platform.add_extension(break_off_pmod) self.submodules.leds = Leds(Cat( #platform.request("user_ledr_n"), #platform.request("user_ledg_n"), platform.request("user_ledr"), platform.request("user_ledg", 0), platform.request("user_ledg", 1), platform.request("user_ledg", 2), platform.request("user_ledg", 3)), led_polarity=0x00, led_name=[ #["ledr", "The Red LED on the main iCEBreaker board."], #["ledg", "The Green LED on the main iCEBreaker board."], ["hledr1", "The center Red LED #1 on the iCEBreaker head."], ["hledg2", "Green LED #2 on the iCEBreaker head."], ["hledg3", "Green LED #3 on the iCEBreaker head."], ["hledg4", "Green LED #4 on the iCEBreaker head."], ["hledg5", "Green LED #5 on the iCEBreaker head."]]) self.add_csr("leds") assert hasattr(self.platform.toolchain, "build_template") if self.platform.toolchain.build_template[0].startswith("yosys "): self.platform.toolchain.build_template[0] =\ self.platform.toolchain.build_template[0].replace("yosys ", "yosys -q ")
@brief <вставьте сюда краткое описание модуля> ''' import time from uart import Uart from sdcard import Sdcard from leds import Leds if __name__ == "__main__": uart1 = Uart() card = Sdcard(uart1) leds1 = Leds(uart1) # leds1.test() time.sleep(1) print(''' Step 1 Set DI and CS high and apply 74 or more clock pulses to SCLK. Without this step under certain circumstances SD-card will not work. For instance, when multiple SPI devices are sharing the same bus (i.e. MISO, MOSI, CS).''') card.preInit() print() print('Переводим сигнал NCS у SD-карты в состояние лог.0') card.select() print()
import RPi.GPIO as GPIO import time from leds import Leds leds = Leds() class Mouvement(): broche = 17 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(broche, GPIO.IN) # Pinout leds GPIO.setup(18, GPIO.OUT) GPIO.setup(24, GPIO.OUT) def detectMove(self, socketIo): previousstate = 0 while True: # Lecture du capteur currentstate = GPIO.input(self.broche,) # Si le capteur est déclenché if currentstate == 1 and previousstate == 0: socketIo.emit('MoveOn', 'mouvement détecté', Broadcast=True) leds.led_on('1') # En enregistrer l'état previousstate = 1 # Si le capteur est stabilisé elif currentstate == 0 and previousstate == 1: socketIo.emit('MoveOff', 'aucun mouvement', Broadcast=True)