0631arraypixybuf ▾element=bufIdx ▾000bufLen ▾=bufIdx ▾=repeatbufIdx ▾fromthru ▾bydoaddcomment ▾Clear response buffer and reset indexfunction clear_buffer add ...arraypixybuf ▾elementbufIdx ▾+ ▾bufIdx ▾1+ ▾item ▾× ▾arraypixybuf ▾elementbufIdx ▾256+ ▾bufIdx ▾1addcomment ▾bufIdx points to LSB of next consecutive value i…bufIdx ▾=item ▾=bufIdx ▾=item ▾=addcomment ▾-- bufIdx advanced by 2 after call addcomment ▾-- put LSB in bufIdx before callingaddcomment ▾Extract 16-bit value from pixybuffunction extract_word add ...run function “clear_buffer”Serial transmitASCII character ▾AEhexadecimalSerial transmitASCII character ▾C1hexadecimalSerial transmitASCII character ▾0EhexadecimalSerial transmitASCII character ▾00hexadecimalrun function “pixy_get_response”run function “extract_version”function pixy_request_versi...00000arraypixybuf ▾element2item ▾21hexadecimal= ▾÷ ▾arraypixybuf ▾element314blockIdx ▾1≥ ▾blockIdx ▾blocksDetected ▾≤ ▾and ▾+ ▾× ▾− ▾blockIdx ▾1146run function “extract_word”item ▾run function “extract_word”item ▾run function “extract_word”item ▾run function “extract_word”item ▾run function “extract_word”item ▾bHeight ▾=bWidth ▾=bYpos ▾=bXpos ▾=bSignature ▾=bufIdx ▾=addcomment ▾Locate start of block valuesifdoblocksDetected ▾=ifdoitem ▾=addcomment ▾Make sure that we have the correct packetbHeight ▾=bWidth ▾=bYpos ▾=bXpos ▾=bSignature ▾=addcomment ▾Reset block valuesaddcomment ▾Extract values for block data indicated by block…function extract_block add...run function “clear_buffer”Serial transmitASCII character ▾AEhexadecimalSerial transmitASCII character ▾C1hexadecimalSerial transmitASCII character ▾0ChexadecimalSerial transmitASCII character ▾01hexadecimalSerial transmitASCII character ▾00hexadecimalrun function “pixy_get_response”run function “extract_resolution”function pixy_request_resol...run function “clear_buffer”maxBlocks ▾constrainfrom1(min) to3(max)Serial transmitASCII character ▾AEhexadecimalSerial transmitASCII character ▾C1hexadecimalSerial transmitASCII character ▾20hexadecimalSerial transmitASCII character ▾02hexadecimalSerial transmitASCII character ▾sigMap ▾Serial transmitASCII character ▾maxBlocks ▾run function “pixy_get_response”maxBlocks ▾=function pixy_request_block...run function “clear_buffer”Serial transmitASCII character ▾AEhexadecimalSerial transmitASCII character ▾C1hexadecimalSerial transmitASCII character ▾14hexadecimalSerial transmitASCII character ▾03hexadecimalSerial transmitASCII character ▾ledRed ▾Serial transmitASCII character ▾ledGreen ▾Serial transmitASCII character ▾ledBlue ▾run function “pixy_get_response”function pixy_set_led run ...run function “clear_buffer”Serial transmitASCII character ▾AEhexadecimalSerial transmitASCII character ▾C1hexadecimalSerial transmitASCII character ▾16hexadecimalSerial transmitASCII character ▾02hexadecimalSerial transmitASCII character ▾lampUpper ▾Serial transmitASCII character ▾lampLower ▾run function “pixy_get_response”function pixy_set_lamps ru...0repeatx times ▾do6Serial receiveASCII character ▾store initem ▾arraypixybuf ▾element=bufIdx ▾item ▾+ ▾bufIdx ▾1bufIdx ▾=arraypixybuf ▾element3repeatx times ▾dopayloadBytes ▾Serial receiveASCII character ▾store initem ▾arraypixybuf ▾element=bufIdx ▾item ▾+ ▾bufIdx ▾1bufIdx ▾=addcomment ▾Get payloadpayloadBytes ▾=addcomment ▾Get size of payloadbufIdx ▾=addcomment ▾Get response headerfunction pixy_get_response ...arraypixybuf ▾element2ifdoelseitem ▾0Fhexadecimal≠ ▾Serial transmittextdecimal number“Error: ”item ▾0000build ▾=minor ▾=major ▾=hardware ▾=6run function “extract_word”item ▾arraypixybuf ▾element8arraypixybuf ▾element910run function “extract_word”item ▾build ▾=bufIdx ▾=minor ▾=major ▾=hardware ▾=bufIdx ▾=item ▾=addcomment ▾Make sure that we have the correct packetfunction extract_version a...arraypixybuf ▾element2ifdoelseitem ▾0Dhexadecimal≠ ▾Serial transmittextdecimal number“Error: ”item ▾00height ▾=width ▾=6run function “extract_word”item ▾8run function “extract_word”item ▾height ▾=bufIdx ▾=width ▾=bufIdx ▾=item ▾=addcomment ▾Make sure that we have the correct packetfunction extract_resolution...“Upper lamp on”10run function “pixy_set_lamps”1000“Lower lamp on”01run function “pixy_set_lamps”1000“Lamps off”00run function “pixy_set_lamps”Terminal new linelampLower ▾=lampUpper ▾=Terminal print textthen a new line✓pause (ms)lampLower ▾=lampUpper ▾=Terminal print textthen a new line✓pause (ms)lampLower ▾=lampUpper ▾=Terminal print textthen a new line✓addcomment ▾Test Lampsfunction lamp_demo add com...“LED is Red”12800run function “pixy_set_led”1000“LED is Green”01280run function “pixy_set_led”1000“LED is Blue”00128run function “pixy_set_led”1000“LED off”000run function “pixy_set_led”Terminal new lineledBlue ▾=ledGreen ▾=ledRed ▾=Terminal print textthen a new line✓pause (ms)ledBlue ▾=ledGreen ▾=ledRed ▾=Terminal print textthen a new line✓pause (ms)ledBlue ▾=ledGreen ▾=ledRed ▾=Terminal print textthen a new line✓pause (ms)ledBlue ▾=ledGreen ▾=ledRed ▾=Terminal print textthen a new line✓addcomment ▾Test RGB LEDsfunction rgb_led_demo add ...run function “pixy_request_resolution”“X Pixels = ”width ▾“Y Pixels = ”height ▾Terminal new lineTerminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓function show_resolution r...run function “pixy_request_version”“Hardware = ”hardware ▾“Firmware = ”major ▾“.”minor ▾“.”build ▾Terminal new lineTerminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓function show_version run ...arraylist ▾element3+ ▾6payloadBytes ▾00repeatx times ▾dobufLen ▾arraylist ▾elementbufIdx ▾+ ▾bufIdx ▾1÷ ▾item ▾16% (remainder after division) ▾item ▾16“ ”+ ▾lineCount ▾1lineCount ▾8= ▾0Terminal new linelineCount ▾=ifdolineCount ▾=addcomment ▾Display 8 bytes per lineTerminal print textthen a new line✓Terminal print numberasHexadecimal ▾then a new line✓Terminal print numberasHexadecimal ▾then a new line✓addcomment ▾Display byte as 2-digit hexbufIdx ▾=item ▾=Terminal new lineTerminal new lineaddcomment ▾Display entire bufferbufIdx ▾=lineCount ▾=bufLen ▾=payloadBytes ▾=addcomment ▾Header (6 bytes) + payload sizeaddcomment ▾Display raw contents of receive bufferaddcomment ▾For Debuggingfunction show_buffer add c...111binary3run function “pixy_request_blocks”÷ ▾arraypixybuf ▾element314“Blocks detected = ”blocksDetected ▾blocksDetected ▾0> ▾1blocksDetected ▾1run function “extract_block”“-- Signature = ”bSignature ▾“-- X Position = ”bXpos ▾“-- Y Position = ”bYpos ▾“-- X Size = ”bWidth ▾“-- Y Size = ”bHeight ▾Terminal new lineTerminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓repeatblockIdx ▾fromthru ▾bydoifdoTerminal new lineTerminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓blocksDetected ▾=maxBlocks ▾=sigMap ▾=addcomment ▾Monitor signatures 1, 2, and 3function show_signatures a...“Left = ”leftSpeed ▾“Right = ”rightSpeed ▾10pause (ms)Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal clear screenfunctiondisplay_servo_speeds addcomment ▾Pixy2_X-Axis_FollowingconstantSIG_1 = 1constantSIG_2 = 2constantSIG_3 = 4constantSIG_4 = 8constantSIG_5 = 16constantSIG_6 = 32constantSIG_7 = 64constantSIG_ALL = 127constantCOLOR_CODES = 128 ▽ ▾array initializepixybufwith64elements ▽ ▾RobotActivityBot 360° ▾initializeRobot set acceleration forspeed ▾blocks to600 ticks/s² (peppy) ▾128“Pixy2 Camera Demo”run function “show_version”run function “show_resolution”run function “rgb_led_demo”run function “lamp_demo”11run function “pixy_set_lamps”repeatforever ▾dorun function “show_signatures”run function “navigate_by_signatures”lampLower ▾=lampUpper ▾=Terminal closeTerminal new lineTerminal print textthen a new line✓ ▽ ▾Serial initialize RX5 ▾TX4 ▾baud19200 ▾modestandard ▾Robot set max speed (+/-) forspeed ▾blocksfunctionnavigate_by_signatures addcomment ▾Monitor signatures 1, 2, and 3111binarysigMap ▾=3maxBlocks ▾=run function “pixy_request_blocks”÷ ▾arraypixybuf ▾element314blocksDetected ▾=ifdoelseblocksDetected ▾0> ▾00Robot drive speedleftright1blocksDetected ▾1repeatblockIdx ▾fromthru ▾bydorun function “extract_block”ifdobSignature ▾1= ▾run function “nagivate_display”leftSpeed ▾=leftSpeed ▾rightSpeed ▾run function “display_servo_speeds”Robot drive speedleftrightrightSpeed ▾=× ▾leftSpeed ▾-1÷ ▾− ▾bXpos ▾1584“-- Signature = ”bSignature ▾“-- X Position = ”bXpos ▾“-- Y Position = ”bYpos ▾“-- X Size = ”bWidth ▾“-- Y Size = ”bHeight ▾Terminal new lineTerminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal print numberasDecimal ▾then a new line✓Terminal print textthen a new line✓Terminal clear screenfunction nagivate_display ...Parallax BlocklyProp ProjectUser: offlineTitle: Pixy2_X-Axis_FollowingProject ID: 0Device: activity-boardDescription: blockly/xml">sigMapbufIdxmaxBlocksitembSignaturelampUpperledRedleftSpeedbufLenbXposlampLowerledGreenwidthhardwarepayloadBytesblocksDetectedbYposledBluerightSpeedbWidthmajorheightlineCountblockIdxbHeightminorbuildCOMMENTPixy2_X-Axis_FollowingSIG_11SIG_22SIG_34SIG_48SIG_516SIG_632SIG_764SIG_ALL127COLOR_CODES128SPACERpixybuf64SPACERabdrive360.hFOR_SPEED600FOR_SPEED1285419200standardSPACERTRUEPixy2 Camera DemolampUpper1lampLower1FOREVERnavigate_by_signaturesCOMMENTMonitor signatures 1, 2, and 3sigMap111maxBlocks3blocksDetected / pixybuf314>blocksDetected0blockIdx= 1blocksDetected1==bSignature1leftSpeed / - bXpos1584rightSpeed * leftSpeed-1leftSpeedrightSpeed00display_servo_speedsFALSELeft = DECTRUEleftSpeedFALSERight = DECTRUErightSpeed10nagivate_displayFALSE-- Signature = DECTRUEbSignatureFALSE-- X Position = DECTRUEbXposFALSE-- Y Position = DECTRUEbYposFALSE-- X Size = DECTRUEbWidthFALSE-- Y Size = DECTRUEbHeightclear_bufferCOMMENTClear response buffer and reset indexbufIdx= 0631pixybufbufIdx0bufIdx0bufLen0extract_wordCOMMENTExtract 16-bit value from pixybufCOMMENT-- put LSB in bufIdx before callingCOMMENT-- bufIdx advanced by 2 after call itempixybufbufIdxbufIdx + bufIdx1item + item * pixybufbufIdx256bufIdx + bufIdx1COMMENTbufIdx points to LSB of next consecutive value in bufferpixy_request_versionBYTEAEBYTEC1BYTE0EBYTE00extract_blockCOMMENTExtract values for block data indicated by blockIdxCOMMENTReset block valuesbSignature0bXpos0bYpos0bWidth0bHeight0COMMENTMake sure that we have the correct packetitempixybuf2==item21blocksDetected / pixybuf314 && >=blockIdx1<=blockIdxblocksDetectedCOMMENTLocate start of block valuesbufIdx + * - blockIdx1146bSignatureitembXpositembYpositembWidthitembHeightitempixy_request_resolutionBYTEAEBYTEC1BYTE0CBYTE01BYTE00pixy_request_blocksmaxBlocks13maxBlocksBYTEAEBYTEC1BYTE20BYTE02BYTEsigMapBYTEmaxBlockspixy_set_ledBYTEAEBYTEC1BYTE14BYTE03BYTEledRedBYTEledGreenBYTEledBluepixy_set_lampsBYTEAEBYTEC1BYTE16BYTE02BYTElampUpperBYTElampLowerpixy_get_responseCOMMENTGet response headerbufIdx0TIMES6BYTEitempixybufbufIdxitembufIdx + bufIdx1COMMENTGet size of payloadpayloadBytespixybuf3COMMENTGet payloadTIMESpayloadBytesBYTEitempixybufbufIdxitembufIdx + bufIdx1extract_versionCOMMENTMake sure that we have the correct packetitempixybuf2!=item0FError: itemhardware0major0minor0build0bufIdx6hardwareitemmajorpixybuf8minorpixybuf9bufIdx10builditemextract_resolutionCOMMENTMake sure that we have the correct packetitempixybuf2!=item0DError: itemwidth0height0bufIdx6widthitembufIdx8heightitemlamp_demoCOMMENTTest LampsTRUEUpper lamp onlampUpper1lampLower01000TRUELower lamp onlampUpper0lampLower11000TRUELamps offlampUpper0lampLower0rgb_led_demoCOMMENTTest RGB LEDsTRUELED is RedledRed128ledGreen0ledBlue01000TRUELED is GreenledRed0ledGreen128ledBlue01000TRUELED is BlueledRed0ledGreen0ledBlue1281000TRUELED offledRed0ledGreen0ledBlue0show_resolutionFALSEX Pixels = DECTRUEwidthFALSEY Pixels = DECTRUEheightshow_versionFALSEHardware = DECTRUEhardwareFALSEFirmware = DECFALSEmajorFALSE.DECFALSEminorFALSE.DECTRUEbuildshow_bufferCOMMENTFor DebuggingCOMMENTDisplay raw contents of receive bufferCOMMENTHeader (6 bytes) + payload sizepayloadByteslist3bufLen + 6payloadByteslineCount0bufIdx0COMMENTDisplay entire bufferTIMESbufLenitemlistbufIdxbufIdx + bufIdx1COMMENTDisplay byte as 2-digit hexHEXFALSE / item16HEXFALSE % item16FALSE COMMENTDisplay 8 bytes per linelineCount + lineCount1==lineCount8lineCount0show_signaturesCOMMENTMonitor signatures 1, 2, and 3sigMap111maxBlocks3blocksDetected / pixybuf314FALSEBlocks detected = DECTRUEblocksDetected>blocksDetected0blockIdx= 1blocksDetected1FALSE-- Signature = DECTRUEbSignatureFALSE-- X Position = DECTRUEbXposFALSE-- Y Position = DECTRUEbYposFALSE-- X Size = DECTRUEbWidthFALSE-- Y Size = DECTRUEbHeight000000000000