Posts

Showing posts from September, 2017

HW 7

#define B0  31 #define C1  33 #define CS1 35 #define D1  37 #define DS1 39 #define E1  41 #define F1  44 #define FS1 46 #define G1  49 #define GS1 52 #define A1  55 #define AS1 58 #define B1  62 #define C2  65 #define CS2 69 #define D2  73 #define DS2 78 #define E2  82 #define F2  87 #define FS2 93 #define G2  98 #define GS2 104 #define A2  110 #define AS2 117 #define B2  123 #define C3  131 #define CS3 139 #define D3  147 #define DS3 156 #define E3  165 #define F3  175 #define FS3 185 #define G3  196 #define GS3 208 #define A3  220 #define AS3 233 #define B3  247 #define C4  262 #define CS4 277 #define D4  294 #define DS4 311 #define E4  330 #define F4  349 #define FS4 370 #define G4  392 #define GS4 415 #define A4  440 #define AS4 466 #define B4  494 #define C5  523 #define CS5 554 #defi...

Project

Image

HW 6

PIR AND LIGHT SENSORS, BLINK MODE INCLUDED WITH COUNT boolean lastPIR = LOW; boolean currentPIR = LOW; const int LED = 10; const int PIR = 2; const int LIGHT = 0; int val = 0; int count = 0; int x = 0; boolean debounce(boolean last) {   boolean current = digitalRead(PIR); //Read the button state   if (last != current) //if it's different...   {     delay(5); //wait 5ms     current = digitalRead(PIR); //read it again   }   return current; //return the current value } \ void setup() {   pinMode (LED, OUTPUT);   pinMode (PIR, INPUT);   Serial.begin(9600); } void loop() {   val = analogRead(LIGHT);   currentPIR = debounce(lastPIR);   if (digitalRead(PIR) == HIGH)   {     digitalWrite (LED, HIGH);     if (lastPIR == LOW && currentPIR == HIGH) count ++;   }   else if (val > 400 && digitalRead(PIR) == LOW)   { ...

HW 5

Wave function: #include <stdio.h> #include <math.h> #define PI 3.1415 int main(void) {   double T1, T2, A1, A2, wl1, wl2, wh1, wh2, wSum=0, wMax=0, wMin=0, t_in, t_fin, t_count, phase;   printf("Input wave 1 period in seconds and wave height in meters: \n");   scanf("%lf", &T1);   scanf("%lf", &wh1);   printf("Input wave 2 period in seconds and wave height in meters: \n");   scanf("%lf", &T2);   scanf("%lf", &wh2);   printf("Input initial time and nubmer of 0.2s increments: \n");   scanf("%lf", &t_in);   scanf("%lf", &t_count);   printf("Input phase shift in multiples of PI: \n");   scanf("%lf", &phase);   A1 = wh1/2;   A2 = wh2/2;   wl1 = (5.13 * pow(T1, 2))*0.3048;   wl2 = (5.13 * pow(T2, 2))*0.3048;   t_fin=t_in+t_count*0.2;   printf("The wavelength of wave 1 is %5.3lf meters.\n", wl1);   printf(...

HW 4

Value of given statement set: #include <stdio.h> #include <math.h> int main(void) { int a = 750; if (a>0)   {   if (a >= 1000)     {     a = 0;     }     else     if (a < 500)       {       a *= 2;       }       else       a *= 10;       } else a += 3; printf("%i", a); return 0; } a = 7500 RBG LED  KNOWN WORKING: const int BLED = 9; //Blue LED on Pin 9 const int GLED = 10; //Green LED on Pin 10 const int RLED = 11; //Red LED on Pin 11 const int BUTTON = 2; //The Button is connected to pin 2 const int RCONT = 3; const int GCONT = 4; //Inputs for controlling analogWrite colors const int BCONT = 5; int count = 0; int R = 0; int G = 0; //Control analogWrite using int of colors so can increment easily int B = 0; boolean lastButton = LOW; //Last Button State boolean...

HW 3

Modify: 1. Use the program to determine the freezing temperatures to go with the following salinity measurements in ppt: 3 8.5 19 23.5 26.8 30.5  2. Modify the program so that it converts and prints the new temperature in degrees Centigrade. (Recall that TF = 9/5 TC + 32 3. Suppose that the data used with the program contained values with the degrees in Centigrade. Would the program need to be changed? Explain.  4. Modify the program so that it interpolates for a salinity, instead of a new freezing temperature. (You may want to refer to the graph below, which contains a plot of this data with the freezing temperature on the x-axis and the salinity on the y-axis.) Temperatures for salinity: 3 ppt = 31.8 8.5 ppt = 31.3 19 ppt = 30.2 26.8 ppt = 29.4 Output in Celsius: #include <stdio.h> #include <math.h> int main(void) { /*  Declare variables.  */ double a, f_a, b, f_b, c, f_c; /*  Get user input from the keyboard.  */ printf(...

HW 2

//Height estimation from femur length: // female height = femur length * 1.94 + 28.7 // male height = femur length * 1.88 + 32 //Height estimation from humerus length: // female height = humerus length * 2.8 + 28.2 // male height = humerus length * 2.9 + 27.9 Estimating height using bone lengths from inches to feet: #include <stdio.h> #include <math.h> int main(void) {   float femur, humerus, Ffemur, Mfemur, Fhumerus, Mhumerus;   again:do   {   printf("Input femur length in inches: ");   scanf("%f", &femur);   printf("Input humerus length in inches: ");   scanf("%f", &humerus);   if (femur > 0 && humerus > 0)   {   Ffemur=(femur*1.94+28.27)/12;   Mfemur=(femur*1.88+32)/12;   Fhumerus=(humerus*2.8+28.2)/12;   Mhumerus=(humerus*2.9+27.9)/12;   printf("Predicted female height from femur: %.2f ft\n", Ffemur);   printf("Predicted male height from femur: ...