WE have learned in earlier lessons that is it poor programming practice to use global variables. In today's lesson we learn how to pass variables and parameters to and from arduino functions by using the pass by reference method.
I came across this while researching for training for a young friend in Nigeria. I like your very gently staged style. And I love that background music ;-)
This was very useful to me. I’ve watched the second Arduino series and the robotics but this clarifies the workings of variables in functions. Always good to plug in with you Paul.
After a hiatus of more than 30 years from programming I started "playing" with Arduino projects. I remembered some of the C lessons, lectures and exercises from back then but things like state machines and pointers I needed refreshing. Your short and to the point lessons are very good for learning and refreshing. Thank you.
Hi Paul, How are you? Leared a lot today by watching your lessons how to pass variables and parameters to and from arduino functions by using the pass by reference method. From now on I will use this easy methode! BOEM!! PS Nice to see we share the same passion : God (at the first place) and ARDUNIO ;-)
Thank you so much, I've struggled to understand the nature and implementation of communicating to and from functions. This lesson cleared my lack of understanding. ❤
I have learned so much from your lessons, both if using the Arduino controller and in the programming language itself. In this lesson, it was all programming. I enhanced the program to use a separate function for ADD, SUBTRACT, MULTIPLY, DIVIDE and finding the SQUARE of the first number. I used REFERENCE to pass parameters back as well as the return command.
I've used the Arduino for several years now but one thing I am not good at is teaching it to others. So whenever someone asks me how to program the Arduino I first direct them to watch your videos. After they've watched most of this series, I then also encourage them to watch other channels such as Ralph S Bacon. Your videos are fantastic and your teaching style works well with beginners. It's the best channel I've found to start learning with.
Paul, your teaching style is great! I have been trying to learn arduino programming for a while. It is finally starting to click. Thanks to your tutorials.
Really good example at the end on the pass by reference and that is what I was interested in. I just did a fast forward got what I needed. For some reason I could not find this in all my google searches. You really do a good job on the videos and they will last forever. Thanks for all your efforts. Thank BOOM was exactly what I wanted!
Hello Paul. I have now watches several of your videos and really getting a lot from them. You explain things clearly and thoroughly. Definitely up with the best. You have helped me get my head around functions and getting cleaner code. Thank you and keep up the great work.
Thank you so much for your videos! I started learning arduino in my spare time and going through your first few lessons got the ball rolling. As I wanted to advance my programs I kept coming back to learn how to do so.
I am behind on providing the comments you've asked for. I am have gone through your entire series on Arduino, Python, BeagleBones, and Raspberry Pi. This is a tremendous teaching medium, and you really have it dialed in, many thanks. Because of you, I bought the RU-vid Red so I can download the series. Like many Texans, I have a long commute to work, and I listen to the audio a couple of times before I sit down to watch them. They are so well done that I can visualize the operations in my mind without needing the visual component. I mentor a HS robotics team (FRC) and they use LabView for the robot. These series have given me a great knowledge base to work off even for other programming languages, but I would love to see you do a series on LabView, especially since I think it would mesh perfectly with your High Altitude Ballooning operations. My only "complaint" would be that I have noticed that you use fewer comments in the code as we go along. I usually FF to the end code, read it, then go back to the beginning to watch the whole thing. That is how I have been gauging my progress, on how well I read it. By the way, I'm an old guy too, just a couple years from retirement. Keep up the good work! I hope your school district recognizes what they have in you. You are leaving an impressive legacy. Best regards.
I finally settled on the BeableBone Blue for most of my robotics, and BeagleBone Black for projects that use LabView. The series you did on Linux was instrumental in moving those projects along. Thankfully, I started computers prior to DOS coming out, so the command line stuff was rusty and dusty, but eventually I remembered most of how that worked. If you are interested in LabView, let me know since I have many contacts at National Instruments. They are a big sponsor of FIRST robotics and wonderful people.
Thank you very much for these lessons. I will now watch your new series. I made a grain bushel estimator to load our trucks on the farm. It uses an amp meter on the grain leg and I calibrate it.
It was a great tutorial. I'm very thankful for the amount of effort and time you put in to teach us Arduino programming. I had tried to learn Arduino before but you are the only tutor I could continue the course to the end. Best wishes Mr.McWhorter.
Very good tutorial. Studied comp sci at uni back in 2003. I'm playing around with Arduino now. Wish this was around back when I was learning to code- would have made the learning more fun and easy.
Hello, Mr.Paul McWhorter. I am a computer science student from Sri Lanka. I love your teaching method. I have watched all the tutorials in this playlist. i want to make a finger print door system for my campus. We are going to fix this finger print door system to class room doors. I need to implement the GSM module with it. for example if one student comes and places his finger, if his finger matches in the database. we need to open the door and also we need to send an SMS to his parent mobile phone. if the finger does not match in the database, the door does not have to open and we need to take a photo of the person who placed the finger in it. We need camera module also with the flash light. It uses the solenoid lock. FEATURES ========= 01. It should a have solenoid lock. 02. if the finger matches in the database, we need to open the door and send an SMS to their guardian. 03. If it doesn't we need to take a photo. Please please, cloud you please make a tutorial how to do it step by step. please....... I believe in you. Thank you so much Sir. I also thank you for the tutorials in this channel.
check the following video. finger print sensor has backup to store the finger prints. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-aYUFmRckc_k.html just search " arduino and finger print " you will get videos with the specification you requested.
Excellent lesson. I typed some notes on this lesson because you covered a LOT of details. I took special note on function construct, order of argument list in tally(). Noted no RETURN in this construct, concur like this better. I looked up the reference operator (&) and I found out that it actually returns the address and retrieves the value of that variable Address....awesome. I assume we don’t have a RETURN because we are using the argument list list instead.....and I also assume this is a void function because we don’t have the RETURN as well. Finally I learned that in the tally() function definition the variables were type cast in the definition argument.....I did try to type cast them in the function body and I got some compiler errors. I LEARNED SOMETHING VALUABLE.......THANKS.
Hi Paul, you have a fantastic teaching style, perfect pace and an obvious understanding of how a student can be guided efficiently to understand the topic. I subscribed to your channel without hesitation. I would love an explanation of how I can input a string of numbers one by one from a touch screen and turn the string into a real number that the rest of the program can make calculations from. My stumbling point is how to handle the decimal part of the string. I also want to validate the number to be between 2 and 25. I have seen many examples of code to read numbers from a keypad or a touch screen keypad, but none have ever handled a number such as 19.7
Sir, You are the BEST !! Your explanations are so well structured that understanding arduino coding has really become very easy, for hobbyists like myself. Thanks and God Bless.
Very well explained and thanks for sharing your knowledge with us, thought i don't get the same results like you do, the code looks identical to mine. I hope you can explain static and volatile variables in another video !
Thank you again for another great lesson Mr. Mcwhorter. I'm excited to be done with these and start your new arduino lessons. I appreciate the walkthrough. I'm going to join your patreon as soon as I can.
Hi Paul, Ignore the picture, that was me in my younger years! First of all, "thank you SOO much". I love your Arduino IDE videos. They are so much easier to understand than any others i have come across. The question: I have been looking at a number of projects for making clocks recently, and almost all of the code use the terms ++x or x++. For a long time i could not work out what it meant, until i found it in the arduino.cc webpage. x++; // increment x by one and returns the old value of x ++x; // increment x by one and returns the new value of x Your code is more "old school", using x=x+1, which in my opinion is the "proper" way to do it. But as i am 59 years old now, and was brought up with the original BASIC, i guess i would prefer your method. However, could you possibly create another video in the Arduino IDE series that covers this topic as clearly all the "young ones" out there are determined to use this newer syntax. There is also a - - x and x - - too (where will it all end).
Thanks for the awesome videos, ou baas! You did a fantastic job explain these concepts to a complete noob. I will look forward to seeing more in the future!
The return is used to send back ONE value in the name of the function e.g. numSquared=sqr(num); //num unchanged If more than one variable needs to be sent back changed then use pass by reference.
I like this, using the Ampersand seems so easy to pass the parrameters back. Because of their position in the Void tally() function name (3rd and 4th) they match up with the position of the parameters in tally(a,b,c,d); so sum will reference to c and difference will reference to d Nice. Great information Paul, I would have found it time consuming to find that answer else where I think. Also because you're not using 'return;' the function type is again Void, please correct me if that last bit is incorrect.
Hi Mr. Paul! I have watched all of your videos and I love the way you teach. I can't wait for the next video! Would you please consider doing one on building a simple LCD menu system that would allow the user to scroll through the menu options and read data from variables. It seems that all examples I can find are menus that allow changes in parameters, or are so complicated that I can't wrap my head around it. When i look at the code examples I am so overwhelmed by it's complexity that I don't even want to try to understand it. There has to be a simpler solution. I'm probably just being lazy, but a simple example might help me understand the basic structure of these examples. Thank you! And don't stop teaching! :-)
Thanks sir for this tutorial. I really wanted to know how to return multiple values from a function. & My waiting is over. Once again thanks a lot. & I learnt lots of Arduino coding techniques from your tutorial and used in my projects. Your techniques of explaining things are really good. & Waiting for next tutorial.
Thanks a lot! I've been looking for a while how to do that and couldn't find. I tried to clean the code to have the function in a different tab (file) and it works.
You, sir, are very good at explaining the innards of this device to an old man (70). Can you speed up the date of your next series? I am now at lesson 9 and I'm worrying at reaching the end of lesson 35. Greetings from The Netherlands.
Hello, i like your videos. they are very helpful for me. Only one suggestion: I practice and learn at night time and please don't do boom. because i setup the volume just right and suddenly you do boom. :) I can't decrease the volume and everybody wakes up and angry. Or volume is too low for my hearing. Thank you for your helpful videos.
I hope there will be a future video explaining how to use created functions from one program into another. For example: creating a function that maps out the IR remote buttons properly in one function in program "a" and sending that data into a different program "b".
Paul, Great job, but can you take this lesson a little further and tie in when to pass by value, when to pass by reference and when to use pointers for the arrays we just learned about?
Hello SirThank you Sir for your kind help in understanding the working of Arduino ,written demonstration is nor readable in some cases due to poor focus.
In C++, & is called reference. It acts like a pointer, so & will change the value of a specific memory address, rather than only using the passed content for calculation. The 0/1 states of the transistors inside the CPU is changed by &.
I'd really like to see examples that do not use the serial monitor as most projects will not use it. For example, how about a reading a POT value, setting it to a variable, and passing that along?
Hi! I know this is an older video but hoping you or someone out there can answer. Can you do this with arrays as well? I wouldn’t know what to google search. Your video made me wonder if that was possible, especially like you said about multiple variables being manipulated in a function. Tried to look, but I don’t think I’m searching the correct terminology…. Thanks. Great video btw.
i was building an obstacle avoidance car and it was realy hard to write the code for each left ,right ,front turns again and again and functions helped ,me alot
Hi Paul, I am a very-soon-to-be mechanical engineer and have been doing a lot of project based learning with Arduinos. Thanks for all the helpful videos. One aspect of arduinos that I am having difficulty understanding is how the baud rate can affect or limit your sampling rate when using the analogRead() command for analog sensors and communicating the data through the serial monitor. For example, my understanding is that the default sampling rate for the analogRead() command with an arduino (16MHz clock speed and 10 bit ADC) is 9615 Hz, but if I set the baud rate for serial communication at anything below 9615 bits/sec * 10 bit ADC = 96150, won't the serial communication baud rate truly dictate the sampling rate instead of the arudinos built in ADC converter properties? Not sure if this is an area you have studied, but if you have any thoughts, I would be interested to hear what you have to say. Thanks
Great, Sir. I want to move some functions to my own library I can use later and I need to know how to pass and get back variables that are not in the same file. The other problem that arises is how to keep variables from those functions alive after I call the functions. ( I receive a string on the serial port, any time I receive something on the port I call the function which is building the string, it adds to the string, check if the string is completed and if not returns to the main loop. If the string is completed, it breaks it to code and variables and returns them. Question is how to keep the string until it's completed(in the library function) and how to return the two variables(from the library function) afterward to the main program
Hello, Mr.Paul McWhorter. Thank you very much for all the Arduino lessons. You can make things very clear. I like to ask you a question: What is the best method to do the following: I connected 6 sensors to the ports A1 to A6. I have to read the values (value1, value2,value3 etc) of those sensors. Can I do that in one function? a function like: for(i=1;i
Thank you Paul for all these nice videos. I followed you New Arduino Tutorials and also many of the old Arduino Lessons. They are all great ones... I have a question, please, is there a way to create function with optional arguments? I surfed the net and i didn't find a clear relevant answer.
Hi Paul great work on all your videos. I have really learned a lot. Can you please do a tutorial on Q learning.I have a robot that i am building and have some sample code, but i am trying to make sense of how the values are passed back and forth.Thank you so much.
Paul I love your lessons. I was wondering if you are planning to do PLC tutorials in the future? Not only ladder logic but also include structured text and fuction block?
H Paul Having an issue with the code as it does not pause to allow entering the second number. It looks correctly coded, but to be sure I went over to your website but can't find it. In fact, I cannot locate "Lesson 35" under "Arduino Lessons" as it stops at 33.
The function did not return anything, as a matter of fact it didn't even finish by 'return' so indeed it is a void function. The way values were "returned" in this case is actually by passing the memory addresses of c and d through sum and difference using that & symbol. Since for instance c and sum now share the same memory address, any modification made to sum within the function will also affect c in the main loop. Nothing is returned.
Hi Paul (: I really appreciate your videos! I learn so much from them. Would it be possible to make a video about accelerometers combined with arduino? It could be really interresting to convert data from the sensor into tilt angles etc. Regards Rasmus
Return will only send back one value. What if I need to work with several variables in one function? Returns are OK, but just my old habits, I like to more formally pass parameters back and forth like shown in this video.