Day_5

comment: I couldn't figure out the modifications for the homework, since I would always get 0 for my results for all of my modification. It's probably my loop and if statement making the code spit out 0. I'm not too sure on how to fix the problem, since I barely understand loops and I find it tricky working with the if statements. On the brighter side, I managed to get the RGB to display the color I want from blue, and red. So that's somewhat of a win. The arduino lab wasn't too difficult, unlike debounce which, stills haunts me.

#include <stdio.h>
#include <math.h>
#define PI 3.141592

int main (void)
{
double per_1, per_2, wh_2, wl_1, wl_2, wl_sum, wave_1, wave_2, wavemax, wave_sum, time;
int wh_1, wavelowest,n_input, phase_1;

 printf("Input period and wave height:\n" );
  printf("Wave 1: \n");
  scanf(" %f %f", &per_1, &wh_1);
  printf("Wave 2: \n");
  scanf(" %f %f", &per_2, &wh_2);
  //printf("Enter desired time: \n");
  //scanf("%f", &time);
  //scanf("%f", n_input);
  wl_1 = 5.13*per_1*per_1;
  wl_2 = 5.13*per_2*per_2;
  wl_sum = wl_1 + wl_2;
  wave_1 = 2*wh_1*sin(2*PI*time*(1/per_1));
  wave_2 = 2*wh_2*sin(2*PI*time*(1/per_2));
  wave_sum = wave_1 + wave_2;

  for (time = 0; time<=200; time+=.005)
    {
      wave_1 = 2*wh_1*sin(2*PI*time*(1/per_1)+phase_1);
      wave_2 = 2*wh_2*sin(2*PI*time*(1/per_2)+phase_1);
      wave_sum = wave_1 + wave_2;
      if(wave_sum > wavemax)
    {
    wavemax == wave_sum;
    wavemax+=.005;
    }
   // else
   // {
   //   if(wave_sum < wavelowest)
    //  wavelowest == wave_sum;
    //  wavemax +=.005;
    //}

    printf("Sum Of Wave Height %9.6f: \n", wavemax);
    printf("Wave Length %9.6f %9.6f : \n", wl_1, wl_2);

    //printf("Specific Height at specified time %9.6: \n,wave_sum);
    }
    return 0;
  }



#define TEMP_PIN A0
#define RED_PIN 9
#define GREEN_PIN 10
#define BLUE_PIN 11

int adc = 0;
int blue = 0, red = 0;

double ReadThermistor(int adc) {

  double resistance = ((1024.0/adc) - 1); 
  double Temp = log(resistance);


  Temp = 1 / (0.003354016 + 0.0002569850 * Temp + 0.000002620131 * Temp * Temp + 0.00000006383091 * Temp * Temp * Temp);
  Temp = Temp - 273.15;            // Convert Kelvin to Celsius
  return Temp;
}

void setLED(int blue, int red){
  analogWrite(BLUE_PIN, blue);
  analogWrite(RED_PIN, red);
}

void setup(){
  Serial.begin(9600);
  pinMode(BLUE_PIN, OUTPUT);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(TEMP_PIN, INPUT);
}

void loop(){
  adc = analogRead(TEMP_PIN);
  int temp = ReadThermistor(adc);
  Serial.println(temp);

  red = map(temp, 20, 40, 0, 255);
  blue = 255 - red;

  setLED(blue, red);
}

 



Comments

Popular posts from this blog

Day_13

Day 18 WH