Skip to main content

Posts

Day 5: Analog Sensors | Repetition Statements

#include <stdio.h> #include <math.h> int main(void){ float pi=3.14159265; float wave1p,wave2p,wave1h,wave2h; float wavelength1,wavelength2,newp,timeinc; float newheight; //Read period and wave height for wave 1 printf("Input the period and wave height of wave 1\n"); scanf("%f %f\n",&wave1p,&wave1h); //Read period and wave height for wave 2 printf("Input the period and wave height of wave 2\n"); scanf("%f %f\n",&wave2p,&wave2h); //Compute and print wavelength for each wave wavelength1=5.13*pow(wave1p,2); wavelength2=5.13*pow(wave2p,2); printf("Wave 1 Wavelength: %5.3f \n Wave 2 Wavelength: %5.3f \n",wavelength1,wavelength2); //Set new period to product of wave periods newp=wave1p*wave2p; timeinc=newp/200; float time=0, wavemax=0, steps=0, sum; while(steps<=199) { newheight=(wave1h+wave2h)*sin(2*pi*time*(1/newp)); if (newheight>wavemax) { wavemax=...

Day 4: RGB Nightlight | Algorithm Development, Conditional Expressions, Selection Statements

Hardware: RGB Nightlight const int red=11; const int green=10; const int blue=9; const int button=4; boolean lastbutton=LOW; boolean currentbutton=LOW; int ledMode=0; void setup() {   // put your setup code here, to run once:   pinMode(button,INPUT);   pinMode(red,OUTPUT);   pinMode(green,OUTPUT);   pinMode(blue,OUTPUT); } boolean debounce(boolean last) {   boolean current=digitalRead(button);   if(last!=current)   {     delay(5);     current=digitalRead(button);   }   return current; } void setMode(int mode) {   //RED   if(mode==1)   {     digitalWrite(red,HIGH);     digitalWrite(green,LOW);     digitalWrite(blue,LOW);   }   if(mode==2)   {     //orange     digitalWrite(red,HIGH);     analogWrite(green,40);     digitalWrite(blue,LOW);...

Day 3: Linear Interpolation, Mathematical Functions, and Arduino Buttons

Figure 1.1 Linear interpolation  assumes that a straight line joins two points f(a) and f(c), and that the value of f(b), where b lies between a and c, lies on this line. Figure 1.2 Cubic spline interpolation  is when the points f(a) and f(c) are joined by a cubic polynomial, and the value of f(b), a function of b, which lies between points a and c, lies on this curve. Formula Assumes a<b<c f(b)=f(a)+((b-a)/(c-a))[f(c)-f(a)] Example 1 The data was given, shown in Figure 1.1 at right. Figure 2.1 Example 2 In the example on the left, we used linear interpolation to find the freezing temperature of certain salinities of water. 1. Problem Statement Use linear interpolation to determine the freezing temperature of water with a certain salinity. 2. Input/Output Description Inputs: first salinity, second salinity, first freezing temperature, second freezing temperature, new salinity. Output: new freezing temperature 3. Hand Example See...

Day 2: Math Operations, Overflow and Underflow, Printf and Scanf

Lab Today we started with our first Arduino lab. We first wanted to make one LED on a breadboard blink, then get 4 LEDs to blink. I was able to do this successfully using the code below. void setup() {   // put your setup code here, to run once: pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(3, OUTPUT); } void loop() {   // put your main code here, to run repeatedly:   digitalWrite(11, HIGH);      delay(500);   digitalWrite(11,LOW);   digitalWrite(10,HIGH);      delay(500);   digitalWrite(10,LOW);   digitalWrite(9,HIGH);      delay(500);   digitalWrite(9,LOW);      delay(100);   digitalWrite(11, HIGH);   digitalWrite(3,HIGH);   digitalWrite(10,HIGH);   digitalWrite(9,HIGH);   delay(100);   digitalWrite(11, LOW);   digitalWrite(3,LOW);   digitalWrite(10,LOW);   digitalWrite(9,LOW); ...

Day 1: Introduction to Programming

Summary We first learned about the different types of applications of programming to various engineering fields. Then we went over the types of computer languages, which included, machine, assembly, and high-level languages. C and C++, the languages used in this course, are both high-level languages. We were introduced to the engineering problem solving methodology, which is as follows: Problem statement Input/output description Hand example Algorithm development Test solution We then did an activity which utilized this. We got together in groups to perform steps 1-3 in trying to find the distance between two points, then tested this on the computer.  After that, we learned about constants and variables, and about different numeric data types.  Problems 1 //First day //Distance formula program //This program calculates distance between two points #include <stdio.h> #include <math.h> int main(void){ //Declared variables double x1=...