Skip to content

Commit 465ee97

Browse files
committed
updated style of examples
1 parent 7c7c875 commit 465ee97

File tree

10 files changed

+136
-176
lines changed

10 files changed

+136
-176
lines changed

examples/AccessPointMode/AP_Basic/AP_Basic.ino

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838

3939
#include <WebGUI.h>
4040

41-
// Function declarations
42-
void buttonGo();
43-
void updateRandomSensor();
44-
void printSystemStatus();
45-
4641
// Pin definitions - change these if using different pins
4742
int TOGGLE_LED_PIN = LED_BUILTIN; // Built-in LED for toggle button
4843
int PWM_LED_PIN = 3; // External LED for brightness control (PWM capable pin)
@@ -112,52 +107,6 @@ void setup() {
112107
Serial.println("===============================================");
113108
}
114109

115-
/*
116-
Function: updateRandomSensor()
117-
118-
This function simulates reading data from a sensor and updates the web display.
119-
In a real project, you would replace the random number generation with
120-
actual sensor readings (temperature, humidity, distance, etc.).
121-
*/
122-
void updateRandomSensor() {
123-
// Check if enough time has passed since the last update
124-
if (millis() - lastSensorUpdate >= UPDATE_RATE) {
125-
126-
// Generate a random sensor value (simulating real sensor data)
127-
// In a real project, this would be something like:
128-
// int sensorValue = analogRead(A0);
129-
// float temperature = readTemperatureSensor();
130-
int randomValue = random(0, 1024); // Random number between 0-1023
131-
132-
// Update the sensor status display on the web page
133-
// The setValue() function accepts different data types:
134-
randomSensor.setValue(String(randomValue) );
135-
// You could also use: randomSensor.setValue(randomValue); // Just the number
136-
137-
// Print to Serial Monitor for debugging
138-
Serial.println("Sensor updated: " + String(randomValue));
139-
140-
// Remember when we last updated
141-
lastSensorUpdate = millis();
142-
}
143-
}
144-
145-
/*
146-
Function: printSystemStatus()
147-
148-
This function prints the current system status to the Serial Monitor.
149-
Useful for debugging and monitoring your system.
150-
*/
151-
void printSystemStatus() {
152-
Serial.println("--- System Status ---");
153-
Serial.println("Toggle LED (Built-in): " + String(ledToggle.isOn() ? "ON" : "OFF"));
154-
Serial.println("PWM LED Brightness (Pin 3): " + String(currentBrightness) + "/255");
155-
Serial.println("Button Press Count: " + String(buttonPressCount));
156-
Serial.println("Update Rate: " + String(UPDATE_RATE) + " ms (fixed)");
157-
Serial.println("Uptime: " + String(millis() / 1000) + " seconds");
158-
Serial.println("--------------------");
159-
}
160-
161110
void loop() {
162111
// CRITICAL: Always call GUI.update() in your main loop
163112
// This processes web requests and updates control values
@@ -238,6 +187,52 @@ void buttonGo() {
238187
// toggleRelay(RELAY_PIN);
239188
}
240189

190+
/*
191+
Function: updateRandomSensor()
192+
193+
This function simulates reading data from a sensor and updates the web display.
194+
In a real project, you would replace the random number generation with
195+
actual sensor readings (temperature, humidity, distance, etc.).
196+
*/
197+
void updateRandomSensor() {
198+
// Check if enough time has passed since the last update
199+
if (millis() - lastSensorUpdate >= UPDATE_RATE) {
200+
201+
// Generate a random sensor value (simulating real sensor data)
202+
// In a real project, this would be something like:
203+
// int sensorValue = analogRead(A0);
204+
// float temperature = readTemperatureSensor();
205+
int randomValue = random(0, 1024); // Random number between 0-1023
206+
207+
// Update the sensor status display on the web page
208+
// The setValue() function accepts different data types:
209+
randomSensor.setValue(String(randomValue) );
210+
// You could also use: randomSensor.setValue(randomValue); // Just the number
211+
212+
// Print to Serial Monitor for debugging
213+
Serial.println("Sensor updated: " + String(randomValue));
214+
215+
// Remember when we last updated
216+
lastSensorUpdate = millis();
217+
}
218+
}
219+
220+
/*
221+
Function: printSystemStatus()
222+
223+
This function prints the current system status to the Serial Monitor.
224+
Useful for debugging and monitoring your system.
225+
*/
226+
void printSystemStatus() {
227+
Serial.println("--- System Status ---");
228+
Serial.println("Toggle LED (Built-in): " + String(ledToggle.isOn() ? "ON" : "OFF"));
229+
Serial.println("PWM LED Brightness (Pin 3): " + String(currentBrightness) + "/255");
230+
Serial.println("Button Press Count: " + String(buttonPressCount));
231+
Serial.println("Update Rate: " + String(UPDATE_RATE) + " ms (fixed)");
232+
Serial.println("Uptime: " + String(millis() / 1000) + " seconds");
233+
Serial.println("--------------------");
234+
}
235+
241236

242237

243238

examples/AccessPointMode/AP_BlinkAnLED/AP_BlinkAnLED.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434

3535
#include <WebGUI.h>
3636

37-
// Function declarations
38-
void updateBlinkBehavior();
39-
4037
// Pin definitions
4138
const int BLINK_LED_PIN = LED_BUILTIN; // LED for blinking control
4239

examples/AccessPointMode/AP_SensorDebug/AP_SensorDebug.ino

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@
4747

4848
#include <WebGUI.h>
4949

50-
// Function declarations
51-
void updateSensorReading();
52-
void checkThreshold();
53-
void printDebugInfo();
54-
5550
// Pin definitions
5651
const int SENSOR_PIN = A0; // Analog sensor input pin
5752

@@ -120,6 +115,27 @@ void setup() {
120115
Serial.println("===============================================");
121116
}
122117

118+
void loop() {
119+
// CRITICAL: Always call GUI.update() in your main loop
120+
// This processes web requests and updates control values
121+
GUI.update();
122+
123+
// Read the sensor value at the specified rate
124+
updateSensorReading();
125+
126+
// Check the sensor value against the threshold
127+
checkThreshold();
128+
129+
// Print debug information every 2 seconds
130+
if (millis() - lastDebugPrint >= 2000) {
131+
printDebugInfo();
132+
lastDebugPrint = millis();
133+
}
134+
135+
// Small delay to prevent overwhelming the system
136+
delay(10);
137+
}
138+
123139
/*
124140
Function: updateSensorReading()
125141
@@ -179,24 +195,3 @@ void printDebugInfo() {
179195
Serial.println("Uptime: " + String(millis() / 1000) + " seconds");
180196
Serial.println("------------------------");
181197
}
182-
183-
void loop() {
184-
// CRITICAL: Always call GUI.update() in your main loop
185-
// This processes web requests and updates control values
186-
GUI.update();
187-
188-
// Read the sensor value at the specified rate
189-
updateSensorReading();
190-
191-
// Check the sensor value against the threshold
192-
checkThreshold();
193-
194-
// Print debug information every 2 seconds
195-
if (millis() - lastDebugPrint >= 2000) {
196-
printDebugInfo();
197-
lastDebugPrint = millis();
198-
}
199-
200-
// Small delay to prevent overwhelming the system
201-
delay(10);
202-
}

examples/AccessPointMode/AP_ServoTest/AP_ServoTest.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ const char* PAGE_TITLE = "3-Servo Test with Attach/Detach Toggle"; // Browser t
5151
#include <WebGUI.h>
5252
#include <Servo.h>
5353

54-
// Function declarations
55-
void updateServoStates();
56-
void printServoStatus();
5754
// getFreeRAM() is now available from WebGUI library
5855

5956
// Pin definitions for servos

examples/AccessPointMode/AP_SwitchPanel/AP_SwitchPanel.ino

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242

4343
#include <WebGUI.h>
4444

45-
// Function declarations
46-
void updateLEDStates();
47-
void printLEDStatus();
48-
4945
// Pin definitions for LEDs - pins 2 through 5
5046
const int LED_PIN_2 = 2;
5147
const int LED_PIN_3 = 3;

examples/StationMode/Station_Basic/Station_Basic.ino

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838

3939
#include <WebGUI.h>
4040

41-
// Function declarations
42-
void buttonGo();
43-
void updateRandomSensor();
44-
void printSystemStatus();
45-
4641
// Pin definitions - change these if using different pins
4742
int TOGGLE_LED_PIN = LED_BUILTIN; // Built-in LED for toggle button
4843
int PWM_LED_PIN = 3; // External LED for brightness control (PWM capable pin)
@@ -119,54 +114,6 @@ void setup() {
119114
Serial.println("===============================================");
120115
}
121116

122-
/*
123-
Function: updateRandomSensor()
124-
125-
This function simulates reading data from a sensor and updates the web display.
126-
In a real project, you would replace the random number generation with
127-
actual sensor readings (temperature, humidity, distance, etc.).
128-
*/
129-
void updateRandomSensor() {
130-
// Check if enough time has passed since the last update
131-
if (millis() - lastSensorUpdate >= UPDATE_RATE) {
132-
133-
// Generate a random sensor value (simulating real sensor data)
134-
// In a real project, this would be something like:
135-
// int sensorValue = analogRead(A0);
136-
// float temperature = readTemperatureSensor();
137-
int randomValue = random(0, 1024); // Random number between 0-1023
138-
139-
// Update the sensor status display on the web page
140-
// The setValue() function accepts different data types:
141-
randomSensor.setValue(String(randomValue) );
142-
// You could also use: randomSensor.setValue(randomValue); // Just the number
143-
144-
// Print to Serial Monitor for debugging
145-
Serial.println("Sensor updated: " + String(randomValue));
146-
147-
// Remember when we last updated
148-
lastSensorUpdate = millis();
149-
}
150-
}
151-
152-
/*
153-
Function: printSystemStatus()
154-
155-
This function prints the current system status to the Serial Monitor.
156-
Useful for debugging and monitoring your system.
157-
*/
158-
void printSystemStatus() {
159-
Serial.println("--- System Status ---");
160-
Serial.println("WiFi Connected: " + String(WiFi.status() == WL_CONNECTED ? "YES" : "NO"));
161-
Serial.println("IP Address: " + WiFi.localIP().toString());
162-
Serial.println("Toggle LED (Built-in): " + String(ledToggle.isOn() ? "ON" : "OFF"));
163-
Serial.println("PWM LED Brightness (Pin 3): " + String(currentBrightness) + "/255");
164-
Serial.println("Button Press Count: " + String(buttonPressCount));
165-
Serial.println("Update Rate: " + String(UPDATE_RATE) + " ms (fixed)");
166-
Serial.println("Uptime: " + String(millis() / 1000) + " seconds");
167-
Serial.println("--------------------");
168-
}
169-
170117
void loop() {
171118
// CRITICAL: Always call GUI.update() in your main loop
172119
// This processes web requests and updates control values
@@ -241,3 +188,51 @@ void buttonGo() {
241188
// resetCounters();
242189
// toggleRelay(RELAY_PIN);
243190
}
191+
192+
/*
193+
Function: updateRandomSensor()
194+
195+
This function simulates reading data from a sensor and updates the web display.
196+
In a real project, you would replace the random number generation with
197+
actual sensor readings (temperature, humidity, distance, etc.).
198+
*/
199+
void updateRandomSensor() {
200+
// Check if enough time has passed since the last update
201+
if (millis() - lastSensorUpdate >= UPDATE_RATE) {
202+
203+
// Generate a random sensor value (simulating real sensor data)
204+
// In a real project, this would be something like:
205+
// int sensorValue = analogRead(A0);
206+
// float temperature = readTemperatureSensor();
207+
int randomValue = random(0, 1024); // Random number between 0-1023
208+
209+
// Update the sensor status display on the web page
210+
// The setValue() function accepts different data types:
211+
randomSensor.setValue(String(randomValue) );
212+
// You could also use: randomSensor.setValue(randomValue); // Just the number
213+
214+
// Print to Serial Monitor for debugging
215+
Serial.println("Sensor updated: " + String(randomValue));
216+
217+
// Remember when we last updated
218+
lastSensorUpdate = millis();
219+
}
220+
}
221+
222+
/*
223+
Function: printSystemStatus()
224+
225+
This function prints the current system status to the Serial Monitor.
226+
Useful for debugging and monitoring your system.
227+
*/
228+
void printSystemStatus() {
229+
Serial.println("--- System Status ---");
230+
Serial.println("WiFi Connected: " + String(WiFi.status() == WL_CONNECTED ? "YES" : "NO"));
231+
Serial.println("IP Address: " + WiFi.localIP().toString());
232+
Serial.println("Toggle LED (Built-in): " + String(ledToggle.isOn() ? "ON" : "OFF"));
233+
Serial.println("PWM LED Brightness (Pin 3): " + String(currentBrightness) + "/255");
234+
Serial.println("Button Press Count: " + String(buttonPressCount));
235+
Serial.println("Update Rate: " + String(UPDATE_RATE) + " ms (fixed)");
236+
Serial.println("Uptime: " + String(millis() / 1000) + " seconds");
237+
Serial.println("--------------------");
238+
}

examples/StationMode/Station_BlinkAnLED/Station_BlinkAnLED.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
#include <WebGUI.h>
3131

32-
// Function declarations
33-
void updateBlinkBehavior();
34-
3532
// Pin definitions
3633
const int BLINK_LED_PIN = LED_BUILTIN; // LED for blinking control
3734

0 commit comments

Comments
 (0)