]> granicus.if.org Git - esp-idf/commitdiff
add adc1 example
authorChu Shu Chen <chushuchen@espressif.com>
Fri, 10 Mar 2017 13:30:30 +0000 (21:30 +0800)
committerChu Shu Chen <chushuchen@espressif.com>
Mon, 20 Mar 2017 06:46:41 +0000 (14:46 +0800)
examples/peripherals/adc/Makefile [new file with mode: 0644]
examples/peripherals/adc/README.md [new file with mode: 0644]
examples/peripherals/adc/main/adc1_test.c [new file with mode: 0644]
examples/peripherals/adc/main/component.mk [new file with mode: 0644]

diff --git a/examples/peripherals/adc/Makefile b/examples/peripherals/adc/Makefile
new file mode 100644 (file)
index 0000000..937dac7
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# This is a project Makefile. It is assumed the directory this Makefile resides in is a
+# project subdirectory.
+#
+
+PROJECT_NAME := adc
+
+include $(IDF_PATH)/make/project.mk
+
diff --git a/examples/peripherals/adc/README.md b/examples/peripherals/adc/README.md
new file mode 100644 (file)
index 0000000..de1532e
--- /dev/null
@@ -0,0 +1,17 @@
+# Example: ADC1
+
+This test code shows how to configure ADC1 and how to use ADC1 get the voltage.
+
+####ADC1 functions:
+
+ * ADC1,CHANNEL_4:GPIO32, voltage range [0v,3.1v],the Data range [0,4095]
+
+####Test:
+ * Please connect the test voltage to GPIO32
+
+
+
+
diff --git a/examples/peripherals/adc/main/adc1_test.c b/examples/peripherals/adc/main/adc1_test.c
new file mode 100644 (file)
index 0000000..c8f4068
--- /dev/null
@@ -0,0 +1,35 @@
+/* ADC1 Example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "freertos/queue.h"
+#include "driver/gpio.h"
+#include "driver/adc.h"
+
+#define ADC1_TEST_CHANNEL (4)
+
+void adc1task(void* arg)
+{
+    // initialize ADC
+    adc1_config_width(ADC_WIDTH_12Bit);
+    adc1_config_channel_atten(ADC1_TEST_CHANNEL,ADC_ATTEN_11db);
+    while(1){
+        printf("The adc1 value:%d\n",adc1_get_voltage(ADC1_TEST_CHANNEL));
+        vTaskDelay(1000/portTICK_PERIOD_MS);
+    }
+}
+
+void app_main()
+{
+    xTaskCreate(adc1task, "adc1task", 1024*3, NULL, 10, NULL);
+}
+
diff --git a/examples/peripherals/adc/main/component.mk b/examples/peripherals/adc/main/component.mk
new file mode 100644 (file)
index 0000000..44bd2b5
--- /dev/null
@@ -0,0 +1,3 @@
+#
+# Main Makefile. This is basically the same as a component makefile.
+#