Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <Windows.h>
- //#include "C:\Program Files (x86)\LabJack\Drivers\LabJackUD.h"
- int main()
- {
- //SECTION 1
- LJ_ERROR lj_cue = 0;
- LJ_HANDLE lj_handle = 0;
- double dblValueAIN1 = 0; // temperature for reference (27°C)
- double dblValueDAC1 = 0; // LED
- double dblValueFIO4 = 0;//PWM signal (buzzer)
- int temperature = 27, times = 0, dutycycle = 0;
- // Section 2
- lj_cue = OpenLabJack(LJ_dtU3, LJ_ctUSB, "1", 1, &lj_handle);
- lj_cue = ePut(lj_handle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 4, 0, 0);//IO location
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc48MHZ_DIV, 0, 0);// TCB
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 48, 0, 0); //TIMER CLOCK FOR DIV
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 1, 0, 0); //enable the timer
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_TIMER_MODE, 0, LJ_tmPWM8, 0, 0);//8-bit PWM
- lj_cue = Go();
- if (times < 3)
- {
- while (dblValueAIN1 < temperature)
- {
- // Section 3
- lj_cue = AddRequest(lj_handle, LJ_ioGET_AIN, 1, 0, 0, 0);
- lj_cue = GoOne(lj_handle);
- lj_cue = GetResult(lj_handle, LJ_ioGET_AIN, 1, &dblValueAIN1);
- printf(" temperature: %f °C\n", dblValueAIN1);
- dutycycle = 0; // buzzer is silent
- sleep(250); //show info every 0.25seconds
- }//exits when temperature is greater than 27
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_DAC, 1, 4.5, 0, 0);//set led voltage to 4.5 turning it on
- lj_cue = GoOne(lj_handle);
- lj_cue = GetResult(lj_handle, LJ_ioPUT_DAC, 1, &dblValueDAC1);
- printf("\n DAC1 = %f \n", dblValueDAC1); // TURN LED ON
- dutycycle = 32768;//buzzer making noise
- lj_cue = ePut(lj_handle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
- lj_cue = eGet(lj_handle, LJ_ioGET_DIGITAL_BIT, 0, &dblValueFIO4, 0);//reset voltage on FIO04
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_DAC, 1, 0, 0, 0); // reset voltage to led turning it off
- lj_cue = GoOne(lj_handle);
- times++;//runs 3 times and exits the program
- }
- //reseting everything again (just to make sure)
- lj_cue = ePut(lj_handle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
- lj_cue = eGet(lj_handle, LJ_ioGET_DIGITAL_BIT, 0, &dblValueFIO4, 0);//reset voltage on FIO04
- lj_cue = AddRequest(lj_handle, LJ_ioPUT_DAC, 1, 0, 0, 0); // reset voltage to led turning it off
- lj_cue = GoOne(lj_handle);
- Close();//leave the program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement