Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
arduino/exercises/05_esp32_LDR/src/main.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
30 lines (24 sloc)
811 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dr Paul Lunn - Coventry University | |
// 9/07/2019 | |
// ESP32 LDR Test | |
#include <Arduino.h> | |
const int SERIAL_0_SPEED = 115200; | |
// The setup() function is called once at the beginning of the program | |
void setup() | |
{ | |
Serial.begin(SERIAL_0_SPEED); // begin serial link | |
Serial.println("ESP32 LDR Test"); // print text onto screen via serial link | |
} | |
// The loop() function runs over and over again forever | |
void loop() | |
{ | |
int adc_reading = analogRead(36); // use adc to read current value | |
float light_level = (adc_reading / 4096.0) * 100; //convert adc to light level % | |
// send results to serial link | |
Serial.print("ADC reading = "); | |
Serial.print(adc_reading); | |
Serial.print(" Light Level = "); | |
Serial.print(light_level); | |
Serial.println("%\n"); | |
delay(1000); // wait for a second | |
} |