Software
Higher Dimensional Arrays
Arrays can be defined with more than two subscripts
Example 1.1
Three-Dimensional array
int b[3][4][2];
The 3 subscripts correspond to the x, y, and z coordinates if the array is positioned at the origin of a 3-dimensional space.
Arrays with more than 3 subscripts are rarely used, and could cause many issues and complicate debugging and maintenance of the program... at least in C. That's a job for Matlab.
Addresses and Pointers
One of the main lessons we learn in Engineering 6, and perhaps in any course taught by Professor Martin Mason, is that if Professor Mason says that something is fun and that the students will love it, there is a very high probability that said topic is, in fact, not fun, and the students will not love it.
So of course, when it was said by Professor Mason that pointers would be loved by all, a ripple of fear traveled through the room.
Luckily, David, who described himself as "the only person last semester who actually liked pointers," had already explained them to me.
Variables used in a program are assigned memory locations, which has a positive integer address that uniquely defines the location. When a variable is assigned a value, it is stored in the corresponding memory location. These can then be called using pointers.
Hardware
Homework
Lab
//Simple Motor Speed Control Program
const int MOTOR=9; //Motor on Digital Pin 9
const int pot=A0; //Potentiometer on analog pin A0
void setup()
{
pinMode (MOTOR, OUTPUT);
}
void loop()
{
int val=analogRead(pot);
val=map(val,0,1023,0,255);
analogWrite(MOTOR,val);
}
Comments
Post a Comment