Asking for Better

Did You Know: Good vs Better

ChatGPT wrote a functioning script that mostly “does the job.” However it is not as easy to understand as it could be, and it takes more memory than examples from other micro:bit tutorials.  For example, it could have used Image.HEART and Image.HEART_Small instead of creating the heart_full and heart_empty custom images.  Also, instead of importing the time module, it could just use sleep(500). All of these changes would make the code easier to read and understand, while using less memory. A better script.

Your Turn: Asking for Easy to Read Code


Why not use Image.HEART and Image.HEART_SMALL instead?  Also, instead of importing time, just use sleep in milliseconds.


Certainly! Here's an updated version of the program using Image.HEART and Image.HEART_SMALL, and using the sleep function in milliseconds:

from microbit import *

while True:
    sleep(500)  # Display the full heart for 500 milliseconds (0.5 seconds)
    sleep(500)  # Display the small heart for 500 milliseconds (0.5 seconds)

This program achieves the same beating heart effect using the built-in heart images and the sleep function with a delay of 500 milliseconds. Feel free to customize the timings or make any other adjustments as needed!



That looks better.


I'm glad you found it better! If you have any more questions or if there's anything else I can help you with, feel free to ask. Happy coding with your micro:bit!

  • Enter the script into the micro:bit Python Editor.
  • Run the script by clicking the Send to micro:bit button.
  • Did it work as ChatGPT described, by displaying beating heart?
  • Was the result identical to the previous AI-generated heartbeat script from the last page?