Tag Archives: Arrays

Arduino Program to Average and Sort Grades

In this video lesson we show how to create a program that will input a list of grades, sort them into descending order, average them, and then find the high and low grades. This is a classic first year college programming assignment. We take you through it step by step. For you convenience, we include the code below.

 

Arduino Uno R4 WiFi LESSON 36: Finding Average of an Array of Numbers on Arduino


 

Below is the code we develop in the video above. It inputs an array of grades, it averages the grades, and then finds the High and Low Grades.

 

Arduino Uno R4 WiFi LESSON 35: Understanding and Using Arrays in Projects


 

In this video lesson we introduce the concept of Arduino Arrays, and illustrate by writing a simple program which inputs and prints a list of grades. The code from the  video above is presented below for your convenience.

 

LESSON 31: Understanding Arduino Arrays

So fare we have used variable declarations like float, int, char and string. We have a variable declaration for any type of data we want to work with, but each of these allows storing a single piece of information.  Often times we want to store more than just one variable, we want to store lists. We can store lists of variables in an array. We can make arrays of all the variable types we already know how to use. For example, if we wanted to store a single grade, we could use the following variable declaration:

float grade;

But, if we wanted to store a list of grades, we could define grades to be an array with the following command:

float grades[15];

This command creates an array called grades, which has 15 slots, so up to 15 grades can be stored. To specify which slot you are working with in your program, you simply reference the slot you are working with inside the brackets. For example:

grades[3]=97;

would set slot 3 in the grades array to the value 97.

Realize when you create an array in arduino, the first slot is slot zero, hence if you wanted to put a grade in the first slot you would use the command:

grades[0]=96;

You can create arrays for all the arduino variable types you are familiar with. You can create int, float, char and string arrays. The video above gives simple to understand examples of how to use arduino arrays.