Advertisement
octavio123

finalprojectcodeHSI

Apr 8th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.52 KB | None | 0 0
  1. #include  <stdio.h>
  2. #include  <stdlib.h>
  3. #include  <Windows.h>
  4. //#include "C:\Program Files (x86)\LabJack\Drivers\LabJackUD.h"
  5.  
  6.  
  7. int main()
  8. {
  9.     //SECTION 1
  10.     LJ_ERROR lj_cue = 0;
  11.     LJ_HANDLE lj_handle = 0;
  12.     double dblValueAIN1 = 0; // temperature for reference (27°C)
  13.     double dblValueDAC1 = 0; // LED
  14.     double  dblValueFIO4 = 0;//PWM signal (buzzer)
  15.     int temperature = 27, times = 0, dutycycle = 0;
  16.     // Section 2
  17.     lj_cue = OpenLabJack(LJ_dtU3, LJ_ctUSB, "1", 1, &lj_handle);
  18.     lj_cue = ePut(lj_handle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
  19.  
  20.     lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 4, 0, 0);//IO location
  21.     lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc48MHZ_DIV, 0, 0);// TCB
  22.     lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 48, 0, 0); //TIMER CLOCK FOR DIV
  23.     lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 1, 0, 0); //enable the timer
  24.     lj_cue = AddRequest(lj_handle, LJ_ioPUT_TIMER_MODE, 0, LJ_tmPWM8, 0, 0);//8-bit PWM
  25.     lj_cue = Go();
  26.  
  27.     if (times < 3)
  28.     {
  29.         while (dblValueAIN1 < temperature)
  30.         {
  31.             // Section 3
  32.             lj_cue = AddRequest(lj_handle, LJ_ioGET_AIN, 1, 0, 0, 0);
  33.             lj_cue = GoOne(lj_handle);
  34.             lj_cue = GetResult(lj_handle, LJ_ioGET_AIN, 1, &dblValueAIN1);
  35.             printf(" temperature: %f °C\n", dblValueAIN1);
  36.             dutycycle = 0; // buzzer is silent
  37.  
  38.  
  39.    
  40.             sleep(250); //show info every 0.25seconds
  41.         }//exits when temperature is greater than 27
  42.        
  43.         lj_cue = AddRequest(lj_handle, LJ_ioPUT_DAC, 1, 4.5, 0, 0);//set led voltage to 4.5 turning it on
  44.         lj_cue = GoOne(lj_handle);
  45.         lj_cue = GetResult(lj_handle, LJ_ioPUT_DAC, 1, &dblValueDAC1);
  46.  
  47.         printf("\n DAC1 = %f \n", dblValueDAC1); // TURN LED ON
  48.         dutycycle = 32768;//buzzer making noise
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.         lj_cue = ePut(lj_handle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
  56.         lj_cue = eGet(lj_handle, LJ_ioGET_DIGITAL_BIT, 0, &dblValueFIO4, 0);//reset voltage on FIO04
  57.         lj_cue = AddRequest(lj_handle, LJ_ioPUT_DAC, 1, 0, 0, 0); // reset voltage to led turning it off
  58.         lj_cue = GoOne(lj_handle);
  59.         times++;//runs 3 times and exits the program
  60.     }
  61.    
  62.     //reseting everything again (just to make sure)
  63.     lj_cue = ePut(lj_handle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
  64.     lj_cue = eGet(lj_handle, LJ_ioGET_DIGITAL_BIT, 0, &dblValueFIO4, 0);//reset voltage on FIO04
  65.     lj_cue = AddRequest(lj_handle, LJ_ioPUT_DAC, 1, 0, 0, 0); // reset voltage to led turning it off
  66.     lj_cue = GoOne(lj_handle);
  67.  
  68.     Close();//leave the program
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement