OLADIPUPO JOHN SHOTADE, 20084356 #9
Serial communication continued
This week the project leader Jason asked me to work on displaying the values that are sent from roborealm to the mocrobit on the LED of the microbit.
Steps involved in displaying the values on the microbit LED
- Established serial connection between roborealm and the microbit
- Opened makecode on a browser window (which showed my already existing code from last week )
- Took the on button A pressed block from the input extension and changed it to A+B.
- Placed the serial write string block from the serial extension and placed it in the on button A+B pressed block.
- Took the serial read string block from the serial exetension and placed it as a value in the serial write string block (meaning the value sent from roborealm will automatically be read into the serial write string block which in turn sends the value back to roborealm).
- Placed the show string block from the basic extension into the on button A+B pressed block under the serial write string block.
- Removed the serial read string block from the serial write string block, duplicated it, placed it back into the serial write string block and placed the duplicate into the show string block.
- Downloaded the code onto the microbit
- Tested the code by sending a value to the microbit from roborealm, pressed the A and B button on the microbit together which showed the value that was sent to the microbit again in the console section of the serial communication window on roborealm as proof that first piece of the code was working (serial write string block).
Problem encountered
- The value that was being sent back to roborealm once the button A+B was pressed wasnt displaying the microbit LED.
- Steps involved to solve the problem encountered
- Placed the clear screen block (to clear the LED screen on the microbit before displaying the value sent by roborealm) in between the serial write string and show string blocks in the on button A+B pressed block.
- Downloaded the code onto the microbit
- Sent a value from roborealm using the normal process already explained before.
- Pressed button A and B which showed the value sent on the console section in the serial communication window in roborealm.
- LED screen on the microbit cleared as it is supposed to but the value sent by roborealm did not still show.
After the steps above Jason came and saw i was on the right path and i told him the problem i was encountering and he explained that everytime that i pressed the button A and B, the value sends up to roborealm and after that it is wiped. Jason then suggested that i should place the value sent from roborealm in a variable and display it. He also suggested that all this could be done in a forever loop block preferably so that everytime a value is sent from roborealm it will automatically be displayed on the microbit LED.
I took on Jason suggestions and did the various steps below:
- Created a variable called received from the variables extension.
- Took the forever loop block from the basic extension.
- Placed the set block from the variable extension into the forever loop block.
- Changed the variable in the set block to the new created variable received.
- Took the serial read string block from the serial extension and placed it in the value part of the set block.
- Placed the show string block from the basic extension into the forever loop block underneath the set block.
- Took the received variable from the variable extension and placed in the value part of the show string block.
What my code created in the steps above does is on a forever loop, set the received variable to whatever value is being sent from roborealm serially and show the value on the microbit LED each time. After the steps above were done the following steps followed to finish up:
- Downloaded the code onto the microbit.
- Tested to see if the code works by sending a value from roborealm to the microbit and the value sent was shown on the microbit LED as proof.
Comments
Post a Comment