Bodgers – Writing Our Own Functions

logo

Hi Everybody

Our WiFi set up worked much better this week with an issue with only one of our routers which decided to give up half way through the session.

We started to write our own functions today, functions are very important in programming as they allow us to run the same code multiple times without rewriting the code several times. Instead, you can put that code inside a function and call the function several times. This has the added benefit that if the function’s code has a mistake, you only have one place in the program to fix it.

If we use names that relate to our function’s operation it will make our code much easier to understand.

Functions make designing and testing bigger programs much easier as we can break the project down to manageable chunks and we can write and test these functions individually.

As we saw last week the GPIO Zero library contains robot functions which turn our robot’s wheels forwards or backwards or in opposite directions to go left or right until we call the robot.stop() function. We are going to take these functions and the sleep() function and put them in functions that will make our robot go forward or backwards  by a specified amount of Centimetres or will turn it left or right by an amount of degrees. This week we wrote a function that makes our robot go forward. See code here. Here are this weeks slides writing-functions . Next week we will write the rest of our functions.

Some Bodgers and their parents have been asking about buying Raspberry Pis but I would advise holding off until we decide on our projects as some people may end up using Arduinos or Raspberry Pi Zeros depending on their project.

However if you want to get one to experiment at home with I would recommend the following sites. https://shop.pimoroni.com/ and https://thepihut.com/ for Raspberry Pi and accessories. If you are buying a case for your Pi I would recommend Pibow Coupé from Pimoroni as the GPIO pins are numbered and easy to get at. For electronic components such as sensors etc.  http://www.bitsbox.co.uk/ are very good, they also do cheap Arduino clones. Avoid starter kits as you should be able to get your hands on stuff like keyboards if you ask friends and relations for them, do get SD cards as you can have different set ups on different cards e.g. Retropi, Kodi.

See you all next week.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s