Тёмный

LESSON 31: Understanding Arduino Arrays 

Paul McWhorter
Подписаться 377 тыс.
Просмотров 69 тыс.
50% 1

You guys can help me out over at Patreon, and that will keep this high quality content coming:
/ paulmcwhorter
In this tutorial we learn how to declare, dimension, and use arrays and array variables with the Arduino. We do a simple averaging program to show the concept

Наука

Опубликовано:

 

2 апр 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 152   
@etc-b-28atharvapatil2
@etc-b-28atharvapatil2 4 года назад
the best mentor anyone could ever get..
@erygion
@erygion 4 года назад
Thank you Mr. Mcwhorter, another great lesson. I had lots of fun with this and modified it with a OLED and leds. I'm learning so much, you're very appreciated sir.
@andrewchiara8617
@andrewchiara8617 6 лет назад
Mr. McWhorter, Thank you for the very clear teaching, laying a solid foundation towards my understanding of working with arrays. I learned a lot!
@rickm4130
@rickm4130 6 лет назад
Thank you for returning to the Arduino series, Great fun!
@garylangley6532
@garylangley6532 6 лет назад
I'm taking a programming class at University of Phoenix and I use your videos a lot for my class discussion. I really enjoy your videos and i learn a lot from them.
@SparkOutUs
@SparkOutUs 3 года назад
I started off on your new arduino series and didnt bother checking this one until now and my god its a gold mine, thanks again!
@MrMikeD28
@MrMikeD28 5 лет назад
That's a very good programming lesson! I like to see the mistakes and how you fixed them. I also didn't know how to prompt the user, now I know. Thanks!
@meagrebones
@meagrebones 6 лет назад
Thanks, that was clear and easy to understand. I like that you made 'deliberate' mistakes to teach us to debug. I'm trying to move on from my cut and paste style of programming so this was a a great help.Looking forward to more.
@tonyw8522
@tonyw8522 4 года назад
Thank you for your efforts Paul. Most of what I know about the arduino code is down to you! 66 years old now and Im still trying to learn. Be well..
@ingeborgsvensson4896
@ingeborgsvensson4896 5 лет назад
Great tutorial. I used and modified this example to calculate the average value of a light intensity sensor. Thank you!
@MrWahjudi
@MrWahjudi 6 лет назад
I just saw this tutorial, Very very clear. English is my third language but you explain everything was very clear for me. Absolutely very excellent teaching.
@TechnoAutomation
@TechnoAutomation 6 лет назад
Thanks a lot. Nicely explained. Waiting for your new lesson.
@bartmanpoet9067
@bartmanpoet9067 2 года назад
Thank you for helping me to work with arrays, please keep making video's. You are a good teacher. I get lost sometimes when you jump around, other than that they cover the material well. I end up re watching the material.
@electronicsexplained287
@electronicsexplained287 6 лет назад
You are a great teacher mr Paul .. Please keep em coming :)
@leginyela
@leginyela 6 лет назад
Thanks again Paul. I appreciate your teaching style
@rbmnewton
@rbmnewton 5 лет назад
Thanks Paul,, just one of your fan in India... Learning about arrays on my way to office today morning....
@elaheparvaee2390
@elaheparvaee2390 3 года назад
I found this series of lessons tonight. While I'm in your channel every day, I've never found them , I don't know why. I'm so happy to discover them, A new opportunity to learn from you, Thank you so much, I appreciate, Elahe
@paulmcwhorter
@paulmcwhorter 3 года назад
Glad you like them!
@redserpent
@redserpent Год назад
Great video. It was good to see you making mistakes and pushing through with the debugging. For the first time I began to understand the meaning of taking the trash out, THank you.
@thambirajahpathmanathan7080
@thambirajahpathmanathan7080 4 года назад
Hallo Sir, your Arduino videos are amazing, I really appreciate your Teaching style is so relaxing that learning with you really is a pleasure.
@jameselliott9397
@jameselliott9397 5 лет назад
Helpful link to all of Paul's amazing Arduino lessons. ru-vid.com/group/PLGs0VKk2DiYx6CMdOQR_hmJ2NbB4mZQn-
@srduke
@srduke 6 лет назад
I'm always talking to my boss about arrays. Never get one though........ I'll get my coat.
@Reach41
@Reach41 6 лет назад
srduke. Funny!
@andymouse
@andymouse 6 лет назад
hahahahhaah!
@MrMikeD28
@MrMikeD28 5 лет назад
lol
@OffGridOverLander
@OffGridOverLander 3 года назад
🤣
@andrewferg8737
@andrewferg8737 3 года назад
Great video. Thanks for educating us!
@thenightwhisper2872
@thenightwhisper2872 6 лет назад
many thanks Sir, pls continue to make more videos, cause we learned from u very much
@twainstasiuk1945
@twainstasiuk1945 6 лет назад
Ok,, thank you once again for an excellent tutorial on arrays! At the end of each lesson,, we have yet another technique for our toolbox not just a copy and paste example we can hope to implement into our work. This is how this tool works and here is a real life example. Excellent teaching! Here's an idea for a show at some point. I know you've done a few shows on interrupts,, and hardware interrupts isn't a big topic,, an easy add to what you've done and it does lead into denouncing code and circuits. I highly suspect anyone who has tried to watch and monitor hardware events has struggled with those topics. PS,,, I think we are ok with you misspelling some code,,making errors,,, sorta makes us feel good to catch stuff and that you are a human,, just like the rest of us. Enjoy the show!
@Constitutionallycorrect
@Constitutionallycorrect 6 лет назад
Once again, a plethera of information!!! It's funny, before i saw your first video i told my girlfriend that i needed someone to turn this code into a bunch of containers, basically like html, so that I can understand it, and here you come with your bucket!! hahahaha, awesome stuff!!!!
@Thefarnworth1
@Thefarnworth1 5 лет назад
MR. McWhorter; I am a 80 year old male and your videos are truly amazing, I really appreciate what you do; your style is so relaxing that learning with you really is a pleasure. Thank you and best regards.
@paulmcwhorter
@paulmcwhorter 5 лет назад
Thanks for the kind words and glad to hear you are enjoying learning.
@ragnarmarnikulasson3626
@ragnarmarnikulasson3626 4 года назад
Exelent tutorial! So we'll explained, clearly a great teacher.
@rukshansheriffdeen195
@rukshansheriffdeen195 6 лет назад
Thank you Sir, you are a great social worker.
@madalinduna4160
@madalinduna4160 4 года назад
Great lesson! Thank you!
@jimnolimit
@jimnolimit 2 года назад
Thank you for making this video.
@naboulsikhalid7763
@naboulsikhalid7763 5 лет назад
good lesson, onetime explained, onetime understood. magic
@yamankhalid1352
@yamankhalid1352 Год назад
Hi Paul, thank you so much for these lessons they helped me a lot. Also, I fixed the sumGrades problem by putting the variable inside the loop function (local variable), so it reset the variable everytime
@Steve-GM0HUU
@Steve-GM0HUU 3 года назад
👍 very nicely explained. Just what I needed to know. Thank you.
@paulmcwhorter
@paulmcwhorter 3 года назад
Great to hear!
@jovane.tech-io
@jovane.tech-io 4 года назад
Just amazing!
@richardbrewer9251
@richardbrewer9251 3 года назад
Paul, this is a great basic lesson. Now I would like to see an advanced lesson on arrays. I have a 20 X 20 neopixel display I am programming using large arrays. Much to my surprise, my Mega 2560 quickly ran out of memory. PROGMEM is the solution to that problem, but I am having trouble understanding the retrieval process. An advanced lesson would probably cover that subject.
@Johann75
@Johann75 2 года назад
Could never understand Arrays at school. Could not believe, I would understand it at the age of 46. Thank you Sir.
@paulmcwhorter
@paulmcwhorter 2 года назад
Glad to hear that
@LizMyers
@LizMyers 6 лет назад
Paul, thanks so much for your videos - you are an EXCELLENT teacher and offer real benefit. The Arduino programming fundamentals are SUPER. In this video you mentioned storing Temp values ove time and plotting them on a graph: could you show us how to do that please? As an added bonus - would be great if we could get an Arduino Touch screen (TFT type) tutorial too or a place to show the temperature graphic. I bought one from EBay and am having difficulty making it do anything! Thanks in advance - Liz
@punjabilog
@punjabilog 2 года назад
Thank you very much Sir for this great video.
@paulmcwhorter
@paulmcwhorter 2 года назад
You are most welcome
@CanalUn
@CanalUn 4 года назад
Thank you very much !
@tonylawless5626
@tonylawless5626 3 года назад
Your awsome keep up the great work
@OutTheGaWoods
@OutTheGaWoods 4 года назад
Hello Sir, I enjoy being able to learn the lessons you teach. I hate to say I got stuck on this one. everything ran smooth until I put in the number of grades, it asked for the grade input twice before I could input the first one . I went back opened a new sketch and rewrote the code line for line ; and the same thing happened again. I will try again tomorrow. The wife just called me in for supper. Thanks again You Are Awesome......
@grantdennert6980
@grantdennert6980 Год назад
I had this problem and worked through it for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!
@toddduffett1378
@toddduffett1378 4 года назад
Hi Paul, Curious to know if you would consider doing a follow up to this video covering Multidimensional Arrays? I love your style and clarity of explanation and think you would do the subject justice.
@rangaswamy8604
@rangaswamy8604 6 лет назад
Good explanation. Could you teach further about assigning values to 3 dimensional arrays and retrieving them using for loops?
@9205aidme
@9205aidme 2 года назад
Very important to have "No line ending" I missed that first time round, and I was scouring the code to see why it was calculating the av too soon! The code was fine!
@nikalfahb2072
@nikalfahb2072 5 лет назад
Good job
@epartsacc
@epartsacc 5 лет назад
Amazing explanation!!! Can you do a video on adding characters to an array to make a string? Then do something with the string like compare it.
@Itzpugs
@Itzpugs 6 лет назад
finally, an explanation that my puny brain comprehends. thank you
@jan42holland
@jan42holland Год назад
Thank you for the Lesson. Can I use this to create a sketch for the ultrasonic sensor with a sketch with sensor A02YYUW? What should you pay attention to?
@tamburaimashonganyika4757
@tamburaimashonganyika4757 2 года назад
its making sense thanks a lot
@paulmcwhorter
@paulmcwhorter 2 года назад
Glad it helped
@orlagh10
@orlagh10 3 года назад
unreal thanks!
@vikasmarkanday6663
@vikasmarkanday6663 5 лет назад
you are awesome !!!
@paulpattyn9070
@paulpattyn9070 4 года назад
always top! thx a lot Paul. could you make one video about multitasking , state machine of ..? Want to control little machine with simultaneously processes.
@bushrafarhat3798
@bushrafarhat3798 6 лет назад
I have followed your videos till now. GREAT WORK. Can you please include line following robot as a project step by step. It's one of the basic Arduino projects but it's not clearly explained on other RU-vid videos. Thanks
@lesliefoster9027
@lesliefoster9027 6 лет назад
Great video, thank you. Could you show me how to enter numbers using a keypad and an LCD display because I'm stuck ? IE. how would you do this lesson with a keypad and LCD display?
@bigbread9000000
@bigbread9000000 5 лет назад
I wonder if it is possible to do a video with arduino and s2 xbee, reading in frames and holding them to do conditional statements?
@sona_YT-jn7up
@sona_YT-jn7up 3 года назад
Thanks man
@capistor1
@capistor1 6 лет назад
kindly explain functions and how to create them according to use and how to trigger a function in result to another trigger.
@alanfairclough3427
@alanfairclough3427 Год назад
Great video. I have trouble with other tutorials that show various ways of doing something rather than just show one way and let that sink in before cluttering one's feeble mind with too much variety from the start. I now have to figure out how to set up an array and input ten light sensor readings and then select the highest number from the array. That is the next challenge.
@paulmcwhorter
@paulmcwhorter Год назад
Perhaps you do not have a feeble mind, but have just had the burden of learning from feeble teachers.
@alanfairclough3427
@alanfairclough3427 Год назад
@@paulmcwhorter No Paul, I have learned from you but your lesson 31 on arrays only covered the basics. Now I need to progress with others. I managed to compare the values and isolate the highest value but don't know how to get the index of the highest value in the array. Other teachers overcomplicate their explanations to show off. You are graciously gentle with beginners. (Humility is a virtue.) I have set up an array arrayS[10] with fix being the highest value in the array, magicNum is the index of the highest value The values are readings off a photoresistor mounted on an actuator sweeping 10 positions in the sky looking for the brightest spot. this is the part that is not working: fix=arrayS[0] for (k=1;k= arrayS[k]){ fix=k; magicNum=k; Serial.print ("k= "); Serial.print (k); Serial.print(" fix= "); Serial.print (fix); Serial.print (" magivNum= "); serial.println(magicNum); } but my magicNum keeps increasing. Do I need an else?
@seditiousmonkeyart
@seditiousmonkeyart 5 лет назад
Hi Paul, I have moved forward with my Arduino coding since beginning to watch your videos, thank you. I am currently trying to use a keypad to enter the RPMs (4 digits) for a motor then have this pass to a 4 digit, 7 segment, LED display and pass through to the code for the motor controller. I finally got my head around using Modulo for the display but I am yet to find a good explanation of how to collect the 4 digits from the keypad. I am still missing some pieces in getting the For loop and array to work together and much of the information I have found is either misleading or incomplete. Any chance you can do a video on collecting multi-digit numbers from a keypad? Many thanks. PS Do you have a Patrion Page
@TechWizCraft
@TechWizCraft 6 лет назад
Hey can you do full tutorial about nrf24lo1?
@royaustin473
@royaustin473 2 года назад
Awesome!
@paulmcwhorter
@paulmcwhorter 2 года назад
Thanks!
@harisahmad9323
@harisahmad9323 6 лет назад
hello sir. I wanted to make an LED cube of [8x8x8] with sound sensor with arduino,,so that cube will bright with beats of sound,,I have done it but every time it repeat the same pattern I wanted it to to bright differently on different beats .do you know how to do that.
@subhopriyojoarder3536
@subhopriyojoarder3536 6 лет назад
please do a video on Hardware Interrupts on Arduino
@raymondzhao9557
@raymondzhao9557 3 года назад
really cool
@ntokozohlatshwayo165
@ntokozohlatshwayo165 5 лет назад
how can i continuously read data from a sensor then compare the current value to the old value?
@robertherzog2087
@robertherzog2087 4 года назад
Other than looping through the array and clearing each value, is there a way to reset the entire array?
@nelsondarwinpaktech3954
@nelsondarwinpaktech3954 3 года назад
Sir....These tutorials are meant for to get some knowledge for less intelligent programmers like me....easy to understand....
@taranagnew436
@taranagnew436 6 лет назад
I think you should do a video on "understanding Arduino interrupts"
@9205aidme
@9205aidme 2 года назад
Great work, but I did find a problem Paul, you need to reset "sumGrades = 0" after you print the average, other wise it keeps adding the previous average to the answer.
@vogesdg
@vogesdg 6 лет назад
Hi Thank you for this excellent education, was wondering I am trying to understand the ESP NOW master example in the ARDUINO IDE, in future maybe you can explain that software to us step by step? Especially this part, cant get my head around it: void sendData() { data++; const uint8_t *peer_addr = slave.peer_addr; Serial.print("Sending: "); Serial.println(data); esp_err_t result = esp_now_send(peer_addr, &data, sizeof(data));
@qzorn4440
@qzorn4440 2 года назад
do you have one on using an arduino mega as a modbus master serial2 rtu rs485 19200N1 to read a panel-meter input registers 30001 30002 then display the values? 🤔thank you
@AliensInc.
@AliensInc. 6 лет назад
One thing that you should show is how to handle Arduino WatchDog. This is for me essential as is can help a malfunction in the code by low power us such.
@blackartista
@blackartista 6 лет назад
Mr. Paul McWhorter can you do something little about GSM(s) in your Arduino Lessons?.With your knowledge I believe we might be missing some techniques on programming GSM
@isuruliyanage7817
@isuruliyanage7817 3 года назад
Hello sir, Thank you for your video. But I have a problem. I`m new to Arduino. Is there function to get minimum and maximum from a float array in Arduino?
@imretoth8150
@imretoth8150 6 лет назад
Beste Mr McWorther, First off i really like your video's. And im getting in to HAB. But how do you let an arduino (or just the Artmel Mega328 talk to a ham transmitter? Or is a ham radio shield used, or is it done with APRS? Greetings, Imre
@paulmcwhorter
@paulmcwhorter 6 лет назад
I really can not advise on this because it is very complex legally. When you start dealing with long distance RF communication, there are lots of laws, and it depends on where you live, and what type of licenses you have.
@imretoth8150
@imretoth8150 6 лет назад
Thanks for the quick reply anyways!
@ajitpattewar6877
@ajitpattewar6877 6 лет назад
hi the videows are wonderful and excelent but when i done coading i am getting an id returned 1 or 2 error what is that please explain sir mr any one
@arniep740
@arniep740 3 года назад
Thanks for this tutorial. One question...Why do you declare "float grades [25]" at the top? I don't see where you use a variable named "grades." Thank you.
@arniep740
@arniep740 3 года назад
Never mind...I see where you do use "grades."
@qkcb
@qkcb 6 лет назад
Are there more similar videos coming soon"
@paparoysworkshop
@paparoysworkshop 5 лет назад
At 24:15 when the error came up and you talked about cleaning up the code, you stated there is no reason to clean up the array itself. Now if you ran the code and the first time you entered 10 grades and the second time you only entered 5, then the first five would be overwritten with new data, but the second five from the first time run would still be in the array. Of course, you only would extract the first five numbers so it really doesn't matter. So I guess my question is, "would that be considered bad programing practice since the array would become cluttered?" Just a thought.
@MrSirPain
@MrSirPain 2 года назад
How would I program the array size when I do not know how many elements (slots) I need? Like a user inputs str of variables.
@paulmcwhorter
@paulmcwhorter 2 года назад
Diminsion it the largest you might need, the use what is needed.
@grantdennert6980
@grantdennert6980 Год назад
To anyone having a problem with the serial monitor skipping the first value: I had this problem and worked through it for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!
@grantdennert6980
@grantdennert6980 Год назад
I guess I could've just finished the video first too haha!
@venkateshgopalaswamy2457
@venkateshgopalaswamy2457 2 года назад
Is it possible to initialize an array and dynamically adjust its length like in python.
@NJ-md8uu
@NJ-md8uu 5 лет назад
can you explain about wire liber
@bholeshankar852
@bholeshankar852 6 лет назад
How to use bootloader atmega328p by the help of arduino uno explain please
@pascalsampatsing5528
@pascalsampatsing5528 6 лет назад
Sir, could I also use return (); in the last command: sumGrades= 0; ?
@mikaelkarlsson9945
@mikaelkarlsson9945 6 лет назад
Pascal Sampatsing There is no need to return() anything, you're still in the loop.. Just "empty the bucket" and you're fine.. (If this were a function, you might want to return the value from the calculation for use in the rest of the main program. Depending on how you declare your variables)
@astaragmohapatra9
@astaragmohapatra9 6 лет назад
We don't need to declare cleanup sumgrades at the end as after one time running the arduino will start reading from the top ,so in declaration sumgrades is initialised with zero
@electronicsexplained287
@electronicsexplained287 6 лет назад
Wrong, It will keep looping in the void loop area
@user-st1ml9rl6b
@user-st1ml9rl6b 6 лет назад
Just for curiosity, are you going to make tutorials for arduino nano or any different types of arduino sir?
@darthvader8433
@darthvader8433 6 лет назад
When you attach the Arduino, simply select the device type. Different devices have different numbers of and numbering of pins, so make sure your connected component pins are corrected in the code. The Arduino code is universal across Arduino models.
@radkarolv.castro6068
@radkarolv.castro6068 4 года назад
Mr. Mcwhorther, I have a question. How to display 30 random numbers using arrays - sorted highest to lowest. I hope you can immediately help me :))) thank you in advance :) from the Philippines
@wooferhound7571
@wooferhound7571 3 года назад
How do you dimension an array ?
@oke806
@oke806 3 года назад
Hello sir, I want user to input data and store it into an array.
@laurenth7187
@laurenth7187 3 года назад
First you should take care about the memory of the Arduino, which might be overflowed by an array... imho. So there should be a memory check routine available ?
@dharmendrachauhan7884
@dharmendrachauhan7884 3 года назад
Hi Sir, I run this average score example in my Arduino uno,nano,etc.then serial.println(please input your grade) line print in Serial monitor two time at a time.my code is as same as like your code. Please help.
@grantdennert6980
@grantdennert6980 Год назад
I had this problem and worked through it for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!
@hunterwilkie4812
@hunterwilkie4812 5 лет назад
every time I open the serial monitor and input the number of grades I woud like to be averaged it skips the odd number. for example, if I wanted to input 5 grades, for the first, third and fifth grades, they will automatically be inputted at 0 and I can only input grades number 2 and 4. it doesn't let me input 1, 3 and 5. and my code is the exact same as yours. no errors. I was wondering if you know the issue or if anyone else has ever had this issue?
@grantdennert6980
@grantdennert6980 Год назад
Yeah I have this same problem it asks twice for the grade
@grantdennert6980
@grantdennert6980 Год назад
I worked through this problem for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!
@dougc3086
@dougc3086 5 лет назад
What if the answer to "How many Grades? " was 26? Wouldn't that cause a stack overflow? How would you avoid this issue in this sketch?
@user-vn7ce5ig1z
@user-vn7ce5ig1z 5 лет назад
It would cause an array-out-of-bounds exception, and he should have at least mentioned it as a thing to look out for. You can deal with it by checking numGrades against your array size, preferably immediately after they input a number that's too large rather than waiting until _after_ they enter 25 grades.
@pierdolio
@pierdolio 6 лет назад
I forced myself to watch your presentation through to the end in case I might have missed something. If I were a student in you class I would definitely fail miserably because I have a hard time following your train of thought, meaning I don't see things the way that you do. To me, an array is like a BINGO grid.
@vikasverma8668
@vikasverma8668 3 года назад
Sir, this program is not working in my Arduino ide
@FlyFSXWithMe
@FlyFSXWithMe 4 года назад
Boom!
@gitagoswami6878
@gitagoswami6878 4 года назад
why not calculate the sum in the loop itself like for(int i=0;i
@davypeleman3672
@davypeleman3672 5 лет назад
Dear Paul, i noticed during your video's you frequently have voice / dry throat problems. Coffee worsens all off that. Just saying that because i really enjoy your lessons and your clear explanations and not to bug you. There are coffees that are milder and in my country we have a good brand of bio- coffee. It's called "coffee can" in dutch "koffie kan". Goodbye upset stomach and dry throat. So maybe you can try something like that. Just wanna help like you do.
@philluvschips3787
@philluvschips3787 Год назад
Has anyone got a solution? I'm using the while (Serial.Available) routine but Arduino just blows right by the 1st and goes to the next while statement, then blows by the 3rd and goes to the 4th etc I have searched all over the internet, used 'if' statement instead, tried a short delay, tried 'flush' .serial, nothing works, this is most painful :(
@paulmcwhorter
@paulmcwhorter Год назад
Is your serial monitor set to no line ending?
@philluvschips3787
@philluvschips3787 Год назад
@@paulmcwhorter OMG, I should really stop doing this until wee hours of he morning :) TY.
Далее
LESSON 32: Understanding Arduino Functions
26:45
Просмотров 63 тыс.
Using Arrays with For Loops
17:24
Просмотров 31 тыс.
DAD LEFT HIS OLD SOCKS ON THE COUCH…😱😂
00:24
O-Zone - Numa Numa yei на русском!🤓
00:56
Просмотров 255 тыс.
What is a Monad? - Computerphile
21:50
Просмотров 596 тыс.