Exemplo n.º 1
1
int main(){

        /* Delay to sleep for human sight*/
        struct timespec a,b;

        a.tv_sec = 0;
        a.tv_nsec = 500000000L;

        /* Golden Rule */
        mraa_aio_context adc_a0;
        uint16_t adc_value = 0;
        float adc_value_float = 0.0;

        /* Initialize Pin */
        adc_a0 = mraa_aio_init(0);
        if (adc_a0 ==NULL){
                return 1;
        }

        /* Read and print values Loopy-Loop */
        for(;;){
                adc_value = mraa_aio_read(adc_a0);
                adc_value_float = mraa_aio_read_float(adc_a0);
                fprintf(stdout, "ADC A0: %d\n", adc_value, adc_value);
                fprintf(stdout, "ADC A0 float: %.3f\n", adc_value_float);
                if(nanosleep(&a,&b)<0){
                        return 1;
                }
        }

        mraa_aio_close(adc_a0);
        return MRAA_SUCCESS;
}
Exemplo n.º 2
0
Arquivo: mqx.c Projeto: chihchun/upm
upm_result_t mqx_get_normalized(const mqx_context dev, float *value)
{
    *value = mraa_aio_read_float(dev->aio);
    if (*value < 0)
        return UPM_ERROR_OPERATION_FAILED;
    return UPM_SUCCESS;
}
Exemplo n.º 3
0
Arquivo: mqx.c Projeto: chihchun/upm
upm_result_t mqx_get_raw_volts(const mqx_context dev, float *value)
{
    *value = mraa_aio_read_float(dev->aio);
    if (*value < 0)
        return UPM_ERROR_OPERATION_FAILED;

    /* Scale by the ADC reference voltage */
    *value *= dev->m_aRef;

    return UPM_SUCCESS;
}
Exemplo n.º 4
0
Arquivo: mqx.c Projeto: chihchun/upm
upm_result_t mqx_get_volts(const mqx_context dev, float *value)
{
    *value = mraa_aio_read_float(dev->aio);
    if (*value < 0)
        return UPM_ERROR_OPERATION_FAILED;

     /* Apply raw scale */
    *value *= dev->m_scale;

     /* Scale to aRef */
    *value *= dev->m_aRef;

    /* Apply the offset in volts */
    *value += dev->m_offset;

    return UPM_SUCCESS;
}
Exemplo n.º 5
0
upm_result_t vdiv_get_computed_volts(const vdiv_context dev, float *value)
{
    // JET - this is wrong.

    *value = mraa_aio_read_float(dev->aio);
    if (*value < 0)
        return UPM_ERROR_OPERATION_FAILED;

     /* Apply raw scale */
    *value *= dev->m_scale;

    /* Scale to the ADC referecen then to vdiv gain */
    *value *= dev->m_aRef * dev->m_vdiv_sw;

    /* Apply the offset in volts */
    *value += dev->m_offset;

    return UPM_SUCCESS;
}
int main() {
	float Rsensor; //Resistance of sensor in K
	// Setup()
	mraa_init();
	mraa_aio_context sensor = mraa_aio_init(analog_Pin_0);
    uint16_t adc_value = 0;
    float adc_value_float = 0.0;

    for (;;) {
        adc_value = mraa_aio_read(sensor);
        adc_value_float = mraa_aio_read_float(sensor);

        Rsensor=(float)(1023-adc_value)*10/adc_value;

        fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
        fprintf(stdout, "ADC A0 read float - %.5f\n", adc_value_float);
        printf("Cant Luz:  %.5f\n", Rsensor);
        usleep(10000);
    }

    mraa_aio_close(sensor);
    return MRAA_SUCCESS;

}
Exemplo n.º 7
0
 /**
  * Read a value from the AIO pin and return it as a normalized float.
  *
  * @returns The current input voltage as a normalized float (0.0f-1.0f)
  */
 float
 readFloat()
 {
     return mraa_aio_read_float(m_aio);
 }