Skip to main content

Day 15: Higher Dimensional Arrays and Pointers | Transistors and Motors

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);
}

Programming


Comments

Popular posts from this blog

Day 25: Python, Graphing, 3D Visualization and Inertial Measurement

Python Arduino Code int trigPin=13; //Sensor Trig pin connected to Arduino pin 13 int echoPin=11; //Sensor Echo pin connected to Arduino pin 11 float pingTime; //time for ping to travel from sensor to target and return float targetDistance; //Distance to Target in inches float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees. void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin, LOW); //Set trigger pin low delayMicroseconds(2000); //Let signal settle digitalWrite(trigPin, HIGH); //Set trigPin high delayMicroseconds(15); //Delay in high state digitalWrite(trigPin, LOW); //ping has now been sent delayMicroseconds(10); //Delay in low state pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microceconds pingTime=pingTime/1000000; //convert pin...

Day 19: Project 2

Our project was a test stand for rocket motors Using an LCD screen, we could choose a display mode, and it would display the selected value. Unfortunately, we were unable to calibrate the pressure sensor, so all we ended up with was a load cell. We used the HX711 library for this. The LCD screen displayed the maximum force experienced during the test Code for MotorSensors.h #ifndef _MOTORSENSORS_ #define _MOTORSENSORS_ #include <LiquidCrystal.h> //Include Liquid Crystal Library #include <HX711.h> //Include HX711 Load Cell library #include "HX711.h" //Include Load Cell header file #include <math.h> //Include math library #define calibration_factor -8815 //set calibration factor #define DAT 3 //define DAT pin #define CLK 2 //define CLK pin #define pressurePin A1 #define tempPin A2 HX711 scale(DAT,CLK);  LiquidCrystal lcd(8,9,4,5,6,7); //Define LCD pins //Initialize variables float maxkg=0;  float currentval=0; float maxforce=0; char mo...