ST / Mbed 2 deprecated HelloWorld_IKA01A1

Dependencies:   X_NUCLEO_IKA01A1 mbed

Fork of HelloWorld_IKA01A1 by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    main.cpp
00004  * @author  CLab
00005  * @version V1.0.0
00006  * @date    2-December-2016
00007  * @brief   Simple Example application for using the X_NUCLEO_IKA01A1 
00008  *          Analog expansion board.
00009  ******************************************************************************
00010  * @attention
00011  *
00012  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00013  *
00014  * Redistribution and use in source and binary forms, with or without modification,
00015  * are permitted provided that the following conditions are met:
00016  *   1. Redistributions of source code must retain the above copyright notice,
00017  *      this list of conditions and the following disclaimer.
00018  *   2. Redistributions in binary form must reproduce the above copyright notice,
00019  *      this list of conditions and the following disclaimer in the documentation
00020  *      and/or other materials provided with the distribution.
00021  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022  *      may be used to endorse or promote products derived from this software
00023  *      without specific prior written permission.
00024  *
00025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031  *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  ******************************************************************************
00037 */ 
00038 
00039 
00040 /* Includes ------------------------------------------------------------------*/
00041 
00042 /* mbed specific header files. */
00043 #include "mbed.h"
00044 
00045 /* Board specific header files. */
00046 #include "XNucleoIKA01A1.h"
00047 
00048 
00049 /* Variables -----------------------------------------------------------------*/
00050 
00051 Serial pc(USBTX, USBRX);
00052 DigitalOut myled(LED1);
00053 
00054 
00055 /* Functions -----------------------------------------------------------------*/
00056 
00057 int main() {  
00058     XNucleoIKA01A1 *analog_expansion_board = XNucleoIKA01A1::instance(
00059         X_NUCLEO_IKA01A1_PIN_INSTRUMENTATION_AMP,
00060         X_NUCLEO_IKA01A1_PIN_CURRENT_SENSING,
00061         X_NUCLEO_IKA01A1_PIN_PHOTO_SENSOR, 
00062         X_NUCLEO_IKA01A1_PIN_WINDOWS_COMP_SIGNAL_1,
00063         X_NUCLEO_IKA01A1_PIN_WINDOWS_COMP_SIGNAL_2,
00064         X_NUCLEO_IKA01A1_PIN_PWM_LED_DRIVER_OUTPUT,
00065         5000
00066     );
00067 
00068     analog_expansion_board->init();
00069     TSZ124 *instr_amp = analog_expansion_board->tsz124;
00070     TSU104 *photo_sensor_wind_comp = analog_expansion_board->tsu104;
00071     TSV734 *led_driver = analog_expansion_board->tsv734;
00072     double duty_cycle = 0;
00073 
00074     /* Printing to the console. */
00075     pc.printf("Analog Application Example\r\n\n");
00076 
00077     /* Looping. */
00078     while(1) {
00079         unsigned int op_amp_voltage = instr_amp->get_voltage();
00080         unsigned int op_amp_current = instr_amp->get_current();
00081         unsigned int photo_sensor_voltage = photo_sensor_wind_comp->get_voltage();
00082         unsigned int wind_com_pin1 = photo_sensor_wind_comp->get_signal1();
00083         unsigned int wind_com_pin2 = photo_sensor_wind_comp->get_signal2();
00084 
00085         pc.printf("\r\nOpAmp measured Voltage(mV): %u", op_amp_voltage);
00086         pc.printf("\r\nOpAmp measured Current(mA): %u", op_amp_current);
00087         pc.printf("\r\nPhotodiode sensor output voltage(mV): %u", photo_sensor_voltage);
00088         pc.printf("\r\nWindows comparator: signal 1 value(pin D2): %u", wind_com_pin1);
00089         pc.printf("\r\nWindows comparator: signal 1 value(pin D4): %u", wind_com_pin2);
00090         pc.printf("\r\nLED Driver: duty cycle: %.2lf %%\r\n", led_driver->set_duty_cycle(duty_cycle));
00091                                           
00092         duty_cycle += 0.1;
00093         if (duty_cycle >= 1) {
00094             duty_cycle = 0;
00095         }
00096 
00097         myled = !myled;
00098         wait(1);      
00099     }    
00100 }