1818// #define CAMERA_MODULE_OV3660
1919
2020#if __has_include("mywifi.h")
21- // I keep my settings in a seperate header file that is in my .gitignore file
21+ // I keep my settings in a seperate header file
2222 #include " mywifi.h"
2323#else
24- // OWEN: todo
25- // Leave as is to create the default accesspoint, or comment out ACCESSPOINT
26- // line and supply your own network SSID and PASSWORD.
27- // bool accessPoint = true;
28- // const char ap_ssid[] = "ESP-CAM-SERVER";
29- // const char ap_password[] = "ESP-CAM-DEMO";
3024 const char * ssid = " my-access-point-ssid" ;
3125 const char * password = " my-access-point-password" ;
3226#endif
3327
3428#include " camera_pins.h"
3529
3630// Status and illumination LED's
37- #ifdef LAMP_PIN // Do we have a LED Illumination Lamp?
38- const int lampPin = LAMP_PIN;
31+ #ifdef LAMP_PIN
32+ int lampVal = 0 ; // Current Lamp value, range 0-100, Start off
3933#else
40- const int lampPin = -1 ;
41- #endif
42- int lampVal = 0 ; // (range 0-100) Start off
43- int lampChannel = 7 ; // a free PWM channel (some channels used by camera)
44- const int pwmfreq = 50000 ; // 50K pwm frequency
45- const int pwmresolution = 8 ; // duty cycle has 8 bit range
46-
34+ int lampVal = -1 ; // disable Lamp
35+ #endif
36+ int lampChannel = 7 ; // a free PWM channel (some channels used by camera)
37+ const int pwmfreq = 50000 ; // 50K pwm frequency
38+ const int pwmresolution = 8 ; // duty cycle has 8 bit range
39+ // https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms
40+ const int pwmIntervals = 100 ; // The number of Steps between the output being on and off
41+ float lampR; // The R value in the PWM graph equation (calculated in setup)
42+
4743void startCameraServer ();
4844
4945void setup () {
5046 Serial.begin (115200 );
51- Serial.setDebugOutput (true ); // OWEN: Change?
47+ Serial.setDebugOutput (true );
5248 Serial.println ();
5349
54- #ifdef LED_PIN
50+ #ifdef LED_PIN // If we have notification LED, set it to output
5551 pinMode (LED_PIN, OUTPUT);
5652 digitalWrite (LED_PIN, LED_OFF);
5753#endif
58-
59- if (lampPin != -1 ) {
60- ledcSetup (lampChannel, pwmfreq, pwmresolution); // configure LED PWM channel
61- ledcWrite (lampChannel, lampVal); // set initial value
62- ledcAttachPin (LAMP_PIN, lampChannel); // attach the GPIO pin to the channel
63- }
54+
55+ #ifdef LAMP_PIN
56+ ledcSetup (lampChannel, pwmfreq, pwmresolution); // configure LED PWM channel
57+ ledcWrite (lampChannel, lampVal); // set initial value
58+ ledcAttachPin (LAMP_PIN, lampChannel); // attach the GPIO pin to the channel
59+ // Calculate the PWM scaling R factor:
60+ // https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms
61+ lampR = (pwmIntervals * log10 (2 ))/(log10 (255 ));
62+ #endif
6463
6564 camera_config_t config;
6665 config.ledc_channel = LEDC_CHANNEL_0;
@@ -124,8 +123,7 @@ void setup() {
124123 WiFi.begin (ssid, password);
125124
126125 while (WiFi.status () != WL_CONNECTED) { // Owen, pulse LED for this.
127- delay (500 );
128- Serial.print (" ." );
126+ delay (250 );
129127 }
130128
131129 // feedback that we are connected
@@ -147,12 +145,12 @@ void setup() {
147145
148146void flashLED (int flashtime)
149147{
150- #ifdef LED_PIN // If we have it, flash it.
148+ #ifdef LED_PIN // Notification LED; If we have it; flash it.
151149 digitalWrite (LED_PIN, LED_ON); // On at full power.
152150 delay (flashtime); // delay
153151 digitalWrite (LED_PIN, LED_OFF); // turn Off
154152#else
155- return ; // or nothing
153+ return ; // No notifcation LED, do nothing
156154#endif
157155}
158156
0 commit comments