Best Python code snippet using fMBT_python
Scope.py
Source:Scope.py  
...58       pygame.draw.line(display,(120,120,120),(v,0),(v,256),1)59   pygame.draw.line(display,(0,0,0),(256,0),(256,256),1)60   pygame.draw.line(display,(0,0,0),(0,128),(512,128),1)61def drawControls():62    drawWords("Time Magnify",10,300,black,backCol)63    drawWords("Voltage Magnify",220,300,black,backCol)64    drawWords("Measure",440,300,black,backCol)65    drawWords("Time",440,320,black,backCol)66    drawWords("Volts",486,320,black,backCol)67    drawWords("Save",540,300,black,backCol)68    drawWords("Time",540,320,black,backCol)69    drawWords("Volts",586,320,black,backCol)70    drawWords("1/"+unichr(0x394)+"Time",540,257,black,backCol)71    drawWords(unichr(0x394)+"Time",540,237,black,backCol)72    drawWords("Saved Time",540,217,black,backCol)73    drawWords("Time",540,197,black,backCol)74    drawWords(unichr(0x394)+"Voltage",540,167,black,backCol)75    drawWords("Saved Voltage",540,147,black,backCol)76    drawWords("Voltage",540,127,black,backCol)77    drawWords("Run Single Freeze Trigger",540,77,black,backCol)78    screen.blit(logo,(540,2))79    updateControls(True)80def updateControls(blank):81    global vDisp82    if blank:83      pygame.draw.rect(screen,backCol,resultsRect,0)  84    if expandT*smples_cm >= 1000:85       drawWords("Time "+str((expandT*smples_cm)//1000)+"mS per division   ",10,280,black,backCol)86    else:87        drawWords("Time "+str(expandT*smples_cm)+"uS per division    ",10,280,black,backCol)88    #volts_cm = int(volts_sample*128*(1000/expandV))89    volts_cm = int(0.0048828125*128*(1000/expandV))90    drawWords("Voltage "+str(volts_cm)+"mV per division",220,280,black,backCol)91    for n in range(0,6): # time option LED92       drawWords("x"+str(1<<n),10+n*30,320,black,backCol)93       drawLED(n,expandT == 1<<n)94    for n in range(6,9): # voltage options95       drawWords("x"+str(1<<(n-6)),220+(n-6)*30,320,black,backCol)96       drawLED(n,expandV == 1<<(n-6))       97    drawLED(9,measureTime)98    drawLED(10,measureVolts)99    drawLED(11,stLed)100    drawLED(12,svLed)101    for n in range(13,17):102       drawLED(n,run[n-13])  103    if measureTime :104       t = (cursorT>>1)*sampleTime / expandT       105       drawWords(" "+trunk(t,5)+" "+unichr(0x3bc)+"S",640,197,black,pramCol) # current time        106       drawWords(" "+trunk(savedTime,5)+" "+unichr(0x3bc)+"S",640,217,black,pramCol)107       drawWords(" "+trunk(t-savedTime,5)+" "+unichr(0x3bc)+"S",640,237,black,pramCol) # delta time108       if t-savedTime != 0 :109          drawWords((trunk(1000000 / abs(t-savedTime),5))+" Hz",640,257,black,pramCol)110    if measureVolts :111       #vDisp = (((1024-cursorV)>>2)-128)*volts_sample * vMag112       vDisp = (((1024-cursorV)>>2)-128)*0.0048828125 * vMag113       delta = vDisp - savedVoltage114       drawWords(" "+trunk(delta,4)+" V",640,167,black,pramCol) 115       drawWords(" "+trunk(savedVoltage,4)+" V",640,147,black,pramCol)116       drawWords(" "+trunk(vDisp,4)+" V",640,127,black,pramCol)117       118def trunk(value, place): # truncate a value string119    v=str(value)+"000000"120    if value>0:121       v = v[0:place]122    else:123       v = v[0:place+1] # extra place for the minus sign124    return v   125    126def drawLED(n,state): # draw LED127    if state : 128        pygame.draw.rect(screen,(240,0,0),LedRect[n],0)129    else :   130        pygame.draw.rect(screen,(240,240,240),LedRect[n],0)131    132def defineControls():133   global LedRect, resultsRect134   for n in range(0,6):135       LedRect[n] = pygame.Rect((10+n*30,336),(15,15))136   for n in range(6,9):137       LedRect[n] = pygame.Rect((220+(n-6)*30,336),(15,15))138   LedRect[9] = pygame.Rect((440,336),(15,15))  # time139   LedRect[10] = pygame.Rect((486,336),(15,15)) # volts140   LedRect[11] = pygame.Rect((540,336),(15,15)) # save time141   LedRect[12] = pygame.Rect((586,336),(15,15)) # save volts142   LedRect[13] = pygame.Rect((545,100),(15,15)) # run143   LedRect[14] = pygame.Rect((580,100),(15,15)) # single144   LedRect[15] = pygame.Rect((628,100),(15,15)) # freeze145   LedRect[16] = pygame.Rect((676,100),(15,15)) # trigger146   resultsRect = pygame.Rect((639,125),(90,153))147    148def plotWave():149    global vMag150    lastX=0 ; lastY=0151    vMag = 2 # adjust voltage scale152    if expandV == 1:153        vMag = 4154    if expandV == 4:155        vMag =1156    drawGrid()157    s = 0 # sample pointer158    for n in range(0, displayWidth, expandT):159        y = (512-inBuf[s])//vMag + chOff160        if n != 0:161            pygame.draw.line(display,(0,200,0),(lastX ,lastY), (n ,y ),2)162        lastX = n163        lastY = y164        s += 1165    if measureTime :166       pygame.draw.line(display,(0,0,255),(cursorT>>1,0), (cursorT>>1,256),1)167       if savedTimeC != -1:168         for n in range(0,256,12):  169            pygame.draw.line(display,(0,0,255),(savedTimeC,n),(savedTimeC,n+6),1)170    if measureVolts :171       pygame.draw.line(display,(255,0,0),(0,cursorV>>2), (512,cursorV>>2),1)172       if savedVoltsC != -1:173         for n in range(0,512,12):  174            pygame.draw.line(display,(255,0,0),(n,savedVoltsC),(n+6,savedVoltsC),1)175    if run[3] : # use trigger176       y = (triggerC-512)//vMag + chOff                                  177       for n in range(0,512,12):  178          pygame.draw.line(display,(255,128,0),(n,y),(n+6,y),1)179      180def drawScope(): # put display onto scope controls181    screen.blit(display,(10,10))182    pygame.display.update()183    184def drawWords(words,x,y,col,backCol) :185    textSurface = font.render(words, True, col, backCol)186    textRect = textSurface.get_rect()187    textRect.left = x188    textRect.top = y    189    screen.blit(textSurface, textRect)190def readArduino(): # get buffer and controls191    global cursorT, cursorV, triggerC, run192    if run[2] : #if in freeze mode funnel data into junk193       for i in range(0,1024):194          junk = sampleInput.read() 195    else: # otherwise read into the buffer   196       for i in range(0,512):197           inBuf[i] = ((ord(sampleInput.read())) << 8) | ord(sampleInput.read())198    cursorT = ((ord(sampleInput.read())) << 8) | ord(sampleInput.read())...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!!
