Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
46 views1 page

Correction TD2 Programmation C Embarquée

This document is a correction for homework assignment 2 on programming C for embedded systems. It includes C code to read the value of a light dependent resistor connected to an analog pin and turn on an LED if the light level is below a threshold of 500. The code initializes the ADC, characterizes it, reads the raw value of the LDR, converts it to voltage, and toggles the LED based on if the voltage is above or below the threshold.

Uploaded by

Kamologne Ulrich
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views1 page

Correction TD2 Programmation C Embarquée

This document is a correction for homework assignment 2 on programming C for embedded systems. It includes C code to read the value of a light dependent resistor connected to an analog pin and turn on an LED if the light level is below a threshold of 500. The code initializes the ADC, characterizes it, reads the raw value of the LDR, converts it to voltage, and toggles the LED based on if the voltage is above or below the threshold.

Uploaded by

Kamologne Ulrich
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

FILIERE : MECATRONIQUE Elément de module

2ème ANNEE Cycle Ingénieur PROGRAMMATION C POUR SYSTEMES EMBARQUES

CORRECTION DES TD/TP

CORRECTION TRAVAIL N°2

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"

adc1_channel_t adc_ldr = ADC1_CHANNEL_0;


#define LED_PIN 22
#define SEUIL 500
static esp_adc_cal_characteristics_t adc1_chars;
uint32_t voltage;
int lum_value
void app_main(void)
{
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12Bit, 0, &adc1_chars);
adc1_config_width(ADC_WIDTH_BIT_12Bit);
adc1_config_channel_atten(adc_ldr, ADC_ATTEN_DB_11);
while (1)
{
lum_value = adc1_get_raw(adc_ldr);
printf("ADC Value: %d \n", lum_value);
voltage = esp_adc_cal_raw_to_voltage(lum_value, &adc1_chars);
printf("Voltage: %d mV \n", voltage);

if (lum_value < SEUIL)


{
gpio_set_level(LED_PIN, 1); // turn on LED
}
else
{
gpio_set_level(LED_PIN, 0); // turn off LED
}
vTaskDelay(500/ portTICK_PERIOD_MS);
}
}

ESI2A - HANAFI AHMED 1

You might also like