Best Python code snippet using fMBT_python
physense_emuX.py
Source: physense_emuX.py
1from guizero import *2led_widgets = []3light_toggle = False4pb_light = None5# Store the led image files in lists6RED_LED_IMAGES = ['src/rLedOff.PNG', 'src/rLedOn.PNG']7YELLOW_LED_IMAGES = ['src/yLedOff.PNG', 'src/yLedOn.PNG']8GREEN_LED_IMAGES = ['src/gLedOff.PNG', 'src/gLedOn.PNG']9BLUE_LED_IMAGES = ['src/bLedOff.PNG', 'src/bLedOn.PNG']10LIGHT_IMAGES = ['src/sun.PNG', 'src/moon.PNG']11def main():12 global led_widgets, pb_light13 app = App(title='Physical Programming Simulator', bg='tan', height=650, layout='grid')14 Text(app, text=' ' * 8, grid=[0, 0])15 Text(app, text='LEDs', grid=[1, 1, 1, 2])16 Text(app, text='rled', color='red', grid=[1, 3])17 red_led = Picture(app, image=RED_LED_IMAGES[0], grid=[1, 4])18 Text(app, grid=[1, 5])19 Text(app, text='yled', color='yellow', grid=[1, 6])20 yellow_led = Picture(app, image=YELLOW_LED_IMAGES[0], grid=[1, 7])21 Text(app, grid=[1, 8])22 Text(app, text='gled', color='green', grid=[1, 9])23 green_led = Picture(app, image=GREEN_LED_IMAGES[0], grid=[1, 10])24 Text(app, grid=[1, 11])25 Text(app, text='bled', color='blue', grid=[1, 12])26 blue_led = Picture(app, image=BLUE_LED_IMAGES[0], grid=[1, 13])27 # Store the led widgets in a list28 led_widgets = [red_led, yellow_led, green_led, blue_led]29 Text(app, text=' ' * 8, grid=[2, 0])30 Text(app, text='Push', grid=[3, 1])31 Text(app, text='Buttons', grid=[3, 2])32 PushButton(app, text='Button_1', command=lambda: button_click(1), grid=[3, 4])33 PushButton(app, text='Button_2', command=lambda: button_click(2), grid=[3, 7])34 PushButton(app, text='Button_3', command=lambda: button_click(3), grid=[3, 10])35 PushButton(app, text='Button_4', command=lambda: button_click(4), grid=[3, 13])36 Text(app, text=' ' * 8, grid=[4, 0])37 Text(app, text='Light', grid=[5, 1])38 Text(app, text='Sensor', grid=[5, 2])39 pb_light = PushButton(app, image=LIGHT_IMAGES[0], width=180,40 height=180, command=toggle_light, grid=[5, 4])41 Text(app, text='buzz', grid=[5, 9])42 Picture(app, image='src/Speaker.png', grid=[5, 10])43 Text(app, text=' ' * 8, grid=[6, 0])44 Text(app, text='Temperature', grid=[7, 1])45 Text(app, text='Sensor', grid=[7, 2])46 Slider(app, horizontal=False, start=150, end=-50, align='top',47 width=50, height=200, command=temperature_changed, grid=[7, 4, 1, 7])48 # Refresh the display every 100 ms to update the leds49 app.repeat(100, led_update)50 app.display()51def toggle_light():52 global light_toggle53 file = open('data/light.txt', 'w')54 # Toggle the images between sun and moon55 if light_toggle:56 pb_light.image = LIGHT_IMAGES[0]57 file.write('on')58 else:59 pb_light.image = LIGHT_IMAGES[1]60 file.write('off')61 file.close()62 light_toggle = not light_toggle63def temperature_changed(degc):64 file = open('data/temperature.txt', 'w')65 file.write(degc)66 file.close()67def button_click(btn_num):68 file = open('data/button_status.txt', 'w')69 file.write('Button_' + str(btn_num))70 file.close()71def led_update():72 # Read the required led status from the data file73 file = open('data/led_status.txt', 'r')74 led_status = file.readline().split()75 file.close()76 # Update the leds to the required status77 if int(led_status[0]) == 0:78 led_widgets[0].image = RED_LED_IMAGES[0]79 else:80 led_widgets[0].image = RED_LED_IMAGES[1]81 if int(led_status[1]) == 0:82 led_widgets[1].image = YELLOW_LED_IMAGES[0]83 else:84 led_widgets[1].image = YELLOW_LED_IMAGES[1]85 if int(led_status[2]) == 0:86 led_widgets[2].image = GREEN_LED_IMAGES[0]87 else:88 led_widgets[2].image = GREEN_LED_IMAGES[1]89 if int(led_status[3]) == 0:90 led_widgets[3].image = BLUE_LED_IMAGES[0]91 else:92 led_widgets[3].image = BLUE_LED_IMAGES[1]...
code.py
Source: code.py
1import board2import time3import touchio4import digitalio5import neopixel6# setup feather trigger7trigger = digitalio.DigitalInOut(board.D0)8trigger.direction = digitalio.Direction.OUTPUT9# setup neopxixel10pixelCount = 3011strip = neopixel.NeoPixel(board.A2, pixelCount, brightness=.2)12strip.fill((255, 0, 0))13strip.show()14# Touch state machine15touch = touchio.TouchIn(board.A1)16touch.threshold += 20017touchCheckInterval = 0.0118previousTouchMilliseconds = 019# LED state machine20ledTransitionInterval = 0.121ledBrightness = 122ledBrightnessDirection = 'down'23previousLedMilliseconds = 024def idleLights(ledBrightness, ledBrightnessDirection):25 if ledBrightness < 0.2:26 ledBrightnessDirection = 'up'27 if ledBrightness >= 1:28 ledBrightnessDirection = 'down'29 if ledBrightnessDirection == 'up':30 ledBrightness += 0.131 else:32 ledBrightness -= 0.133 strip.fill((255, 0, 0))34 strip.brightness = ledBrightness35 strip.show()36 return ledBrightness, ledBrightnessDirection37def manageTouch():38 print('checking touch')39 strip.show()40 if touch.value:41 print("A1 touched!")42 trigger.value = True43 time.sleep(0.01)44 trigger.value = False45 for i in range(11):46 if i % 2 == 0:47 strip.fill((255, 255, 255))48 else:49 strip.fill((148, 0, 211))50 strip.show()51 time.sleep(0.001)52 time.sleep(1)53while True:54 currentMilliseconds = time.monotonic()55 if currentMilliseconds - previousLedMilliseconds > ledTransitionInterval:56 previousLedMilliseconds = currentMilliseconds57 ledBrightness, ledBrightnessDirection = idleLights(58 ledBrightness, ledBrightnessDirection)59 if currentMilliseconds - previousTouchMilliseconds > touchCheckInterval:60 previousTouchMilliseconds = currentMilliseconds...
7seg.py
Source: 7seg.py
1import RPi.GPIO as led2import time3led.setmode(led.BOARD)4led.setwarnings(False)5# {"a" : 7, "b" : 11, "c" : 19, "d" : 15, "e" : 13, "f" : 5, "g" : 3}6led_pins = [3, 5, 7, 11, 13, 15, 19, 21]7led_pins_0 = [5, 7, 11, 13, 15, 19]8led_pins_1 = [11, 19]9led_pins_2 = [7, 11, 3, 15, 13]10led_pins_3 = [7, 11, 19, 15, 3]11led_pins_4 = [5, 3, 11, 19]12led_pins_5 = [7, 5, 3, 19, 15]13led_pins_6 = [7, 5, 3, 19, 15, 13]14led_pins_7 = [7, 11, 19]15led_pins_8 = [3, 5, 7, 11, 13, 15, 19]16led_pins_9 = [3, 5, 7, 11, 15, 19]17digits = [led_pins_0,18led_pins_1,19led_pins_2,20led_pins_3,21led_pins_4,22led_pins_5,23led_pins_6,24led_pins_7,25led_pins_8,26led_pins_9]27for x in led_pins:28 led.setup(x, led.OUT)29 led.output(x, 0)30 31while True:32 for i in digits:33 for j in i:34 led.output(j, 1)35 time.sleep(1)36 for j in i:...
Check out the latest blogs from LambdaTest on this topic:
Collecting and examining data from multiple sources can be a tedious process. The digital world is constantly evolving. To stay competitive in this fast-paced environment, businesses must frequently test their products and services. While it’s easy to collect raw data from multiple sources, it’s far more complex to interpret it properly.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!