It's Wednesday the 30th of October, 2019, and this is HPR episode 2933 entitled, I walk through my Pi-Face CAD Pithing Code Part 1. It's part of a series, a little bit of Python, and it's the 50th anniversary show for Mistrex. The show itself is about 50 minutes long and carries an explicit flag. The summary is, in this series I do a whirlwind tour of the Pi-Ting Code I developed for my Pi-Face CAD board. This episode of HPR is brought to you by AnanasToast.com. Get 15% discount on all shared hosting with the offer code HPR15, that's HPR15. Bit your web hosting that's Aniston Fair at AnanasToast.com. Hello and welcome, hacker public radio din's, my name is Mr. X, and welcome to this podcast. I've got to start as usual by thanking the people HPR for making this service available to us all, and it really is a truly invaluable service to bring to all of us. HPR is a community-led podcast provided by the community for the community. That means you can contribute to just pick up a microphone, MP3 player, mobile phone, computer if you've got one, hit the card on off you go, and then send it in simple as that. Well it's been a while since I've recorded anything, and feeling decidedly rusty. I wasn't sure if I was going to record this episode, I hummed and heard about it for quite a while, so in this episode I thought I'd do a quick run-through try to keep it quick off my Python program, which I use on my PyFace command and display board, which sits in top of my Raspberry Pi, which I use to control mock-p on another Raspberry Pi upstairs it allows me to play and pause a track playing on mock-p, music and command line player, and allows me to go to the next track, previous track with so-and-so forth, I explained all that in a previous episode hopefully, I've just turned it on and it says there are only 23 days to a free HPR slot, and the blinks they're kind of side as a glowing green, which means this an adequate, I won't say plenty, it's never plenty, adequate number of shows in the queue, can we never want to admit that, there's never adequate, there's always space for more, so why don't you take a picture of something and give us some shows, I've forgotten to put some shows, more than we'd know what to do with, so-way, yes, one with the shoe, so this is going to be a bit off the cuff, so I've got, I'll just move screens here, I don't know, I'll just quit the program with a queue and I'm logged into the, my Raspberry Pi with the Pyphys board installed, a script, where's it now? So I've got a copy here open and of CADAS, so where am I what was I seeing right, so this script has been, I've been in development for quite a long time and nowadays I hardly ever took it, it can go months without change, I did do some changes recently, which I talked about later on, as I come to them, my most recent changes, but I'm just looking back at the date stamps on the script, so I've got a backup script which backs up my scripts directory, it's up, well, TJ, TJ, TJ, TJ, Z, and let me just see, yeah, so, so the very earliest version of my scripts folder goes back to 2014, so I should have done that I've been working with, so it might be in 2014 when I started working, and I'm not quite sure, but it goes back a long way anyway, and the most recent one was, the most recent change was in the fifth of December 2018, just for him to say, so the program's called CADASMENU.py it's a Python program, basically, so I'll just, I don't have that open, it's a CIO, yes, here we go, so I had a few problems with an update and I had to go back from Python 3 to Python 2, but I'll explain that in another podcast, can I ignore that for now? Hopefully, I won't tweak it too much, I think one that, as I said, I wondered whether to release this or not, because it's always, yeah, I'm asking for you, I think about releasing code into the wild, you know, it's going to show how a rubbish program I am, and all of my sticks and terrible things, and I'm not, I'm not, I'm not, I'm not sure, is it spelling and how has I been, so they will have a Canadian even a season, a terrible spelling in this, and this is script, then English, but then I suppose, well, I'm the operational programmer, I'm a hobby programmer, I, when I, it's a good thing, it's a course, but Python's so easy to play with it, you can pull code together really quickly, easily, probably you can write quite nasty code quite easily as well, of course, but, and I was kind of impatient just to build this thing up, and it kind of morphed from a very simple thing, it wasn't, it wasn't all planned out like a good software, but a software should be, you know, it was, oh, what they want to do well, I mean, because the first thing I want to do, was to able to pause and please, pause and play audio playback from my Raspberry Pi upstairs, it was running mock P, mock P being the command line player, which plays audio, and I wanted to run, I was able to, to be able to, at the very least, play and pause, toggle between play and pause, on that, that was really all I needed to achieve, and that was probably the very first thing that I managed, you know, mock P can be told, I think it's a dash capital G, I think, mock P is based dash G, dash capital G, it's always between play and pause, and that's all you need to send to the Pi upstairs, and that would do it, and click to my Raspberry Pi upstairs as I said, of course headphones, I'll probably explain to all this before, so maybe we're going to all that, so anyway, I've got a section, a front here, which starts things to do, and I hope I'll stuff in there, which, if you're bored, you can read over, because I'm a quite a long time, actually, I've got a section, could start here, at line 140, so the really clever thing is, it's a Pi-face CAD module, which comes with the Pi-face board, that's what all the clever stuff is really, I'm just using the advantage of this module written by the Pi-face people, and of course there's a new version, I think, the new version of Pi, and this is, of course, some of the weaknesses, you know, the distribution updates, and then the drivers don't work in things, and then you can compatibility, and all this sort of thing, so that's a problem, it's getting a bit long in the tooth now, and I've barely had the will and inclination to get it working after the last debut upgrade, but that's not our story, so yeah, so the whole palamogels I am putting into the Python project, I want to go through that, that the most recent thing I did was below that I've got a section for a global variables, and I had littered through the code that had the address for my internal IP address, the Raspberry Pi, which I was controlling, and all littered through the code was, you know, Pi at 192.168.1.0 whatever, you know, and what I really should have had was a global variable called remote, a global variable basically, so that you could just refer to that, if you ever needed to change that IP address, you would change it on one place, and not 15 places or whatever, so that was the thing I did very recently, and I called that variable remote device, so remote device equals my case Pi at 192.168.1.13, so I probably rely, well, definitely rely to heavily on global variables, and I'm not going to be terribly consistent with global variables either, because from documentation I read online, I was under the understanding that you need to use a command to allow you to use global variables in a function, you know, of course, I'm certainly programming in Python, and I can't even know what the, what the, what the command was, let me just see, you know, what was that command, oh, global, that was it, so for example, I've got a linearity global space, menu, so that allows you to use the global variable menu. Now, when I didn't actually understand what was, if you, I, I, and I'm still not, I haven't done anything, I haven't done any experiments to really prove this, but it must be the case, that if you don't use, if you've got a global variable, so you've got a, maybe, okay, so that definitely, you know, a, a private variable and global, a private variable and normal variable and a global variable is that a normal variable is a scope, if you've got a, a normal variable inside a, a function in a, a, the other functions outside, I outside that can't see that, that variable, picking this very complicated, I don't know, but a global variable of its, at the top of the code, then, it, outside all the functions in every day, all the functions can see that, global variable. But the way it works is, I think, is if you don't use the command global, then you can still access that global variable, you just can't change it. So, in some cases, I've got, I'm using the command global, institutions where I don't actually need to change that global variable. So, in reality, for safety, I shouldn't be using the word global, so you just ignore it all together and just I can read the, the contents of the global variable, but I don't need to change it. Um, I think that's how that, that basically works. How do they get into that, I don't know. Anyway, so I've got too many global variables. Um, you should really, um, understanding is that you should really, um, feed values in a note of functions rather than, um, right past, past values, interfunctions rather than relying global variables. And I remember, I treated explaining to me many, many years ago when I was doing a course on, um, you know, what was it, it's not Python, what was it, uh, Pascal, that was it. I need to say, well, it's a bit like, um, imagine you, you, uh, you're, you're outside the field, and you want to cross a field to get the other side, uh, and there's a, there's a, there's a Boolean in the middle of the field, this is well, you can either, you can either walk around outside edge where it's nice and safe or you can jump over the fence and turn around to the other side. And I say, well, it's a bit like that, you know, if, if you, if you're, um, using global variables, that, then another function could come, go in and change that variable to something else, the, you're not aware of, and, um, and muck up your, um, your code basically, whereas if you're passing the value in, then you're not affecting the, the global variable. Anyway, whatever, that'll come from, um, a bit of watch, my time, how long has this been going for 15 minutes? Oh, this is disaster. This can be far too long. Okay, I think that's about enough for this episode, uh, I think it's a good place to stop it. If you want to contact me, then I can be contacted that, Mr. X at hpr at googlemail.com. Let's m-r-x at hpr at symbol googlemail.com. So tune in next time for the next setting episodes of Hacker, public radio, radio, radio, radio.org. We are a community podcast network that release the shows every weekday Monday through Friday. Today's show, like all our shows, was contributed by a Hpr listener like yourself. If you ever thought of recording a podcast, then click on our contributing to find out how easy it really is. Hacker public radio was founded by the digital.com, and the informomicon computer club, and it's part of the binary revolution at binref.com. If you have comments on today's show, please email the host directly, leave a comment on the website or record a follow-up episode yourself. On this otherwise status, today's show is released on the creative comments, attribution, share a light, speed of your license.