Charles Tritt / Mbed 2 deprecated FanOnOff

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Wed Apr 21 21:43:07 2021 +0000
Parent:
1:4647b43d61ef
Commit message:
Simple fan on-off controller. Includes compile time setting of setpoint and hysteresis values. Sends analog input and digital output to serial port for monitoring. Tested on Nucleo L476RG board. Should work with F411RE boards.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 4647b43d61ef -r 220c6c5adf15 main.cpp
--- a/main.cpp	Mon Mar 27 14:29:20 2017 +0000
+++ b/main.cpp	Wed Apr 21 21:43:07 2021 +0000
@@ -1,40 +1,44 @@
 /*
-    Project: analogRead_Overlaods
+    Project: FanOnOff
     File: main.cpp
     
-    Reads from analog input, streams ASCII text to std serial using printf, and
-    lights onboard LED. Also demonstrates use of floating point literal sufix to 
-    eliminate warning and int constants for HIGH and LOW. This version uses
-    overloaded operators and sends LED state read from DigitalOut object.
+    Reads from analog input, streams ASCII text to std serial using printf. 
+    Controls a fan. Includes setpoint and hysteresis values.
     
     Written by: Dr. C. S. Tritt
-    Created: 3/26/17 (v. 1.0)
-    
+    Created: 3/26/17 (as Nightlight)
+    Revised: 4/21/21 (v. 1.0)
 */
 #include "mbed.h"
 
 const int HIGH = 1; // Optional, but makes code more readable.
 const int LOW = 0; // Optional, but makes code more readable.
  
-AnalogIn analog_value(A0);
+AnalogIn analog_in(A5);
  
-DigitalOut led(LED1);
+DigitalOut fan(D13); // Same as user LED.
 
 int main() {
-    float value; // Value to be read and sent to serial port.
+    float sp = 0.5; // Declare and set setpoint value.
+    float hyst = 0.02; // Declare and set hysteresis value.
+    float t; // Temperature value read, sent to serial port & used.
     
     printf("\nAnalogIn example\n");
     
     while(true) {
-        value = analog_value; // Read the analog input value (0 to 1)
-        printf("Value = %f\n", value); // Send value as text via serial port.
-        if (value > 0.5f) { // Activate built-in LED. The f is optional.
-          led = HIGH;
+        t = analog_in; // Read the analog input value (0 to 1).
+        printf("Temperature (0 to 1) = %f\n", t); // Send out serial port.
+        
+        if (fan) { // That is, fan == HIGH (1)
+            if (t < (sp - hyst)) { // Activate built-in LED. The f is optional.
+                fan = LOW;
+            }
+        } else { 
+            if (t > (sp + hyst)) {
+                fan = HIGH;
+            }
         }
-        else {
-          led = LOW;
-        }
-        printf("LED = %d\n", (int) led); // Send LED state as serial text.    
+        printf("Fan = %d\n", (int) fan); // Send fan state as serial text.    
         wait(0.25); // 250 ms
     }
-}
+}
\ No newline at end of file
diff -r 4647b43d61ef -r 220c6c5adf15 mbed.bld
--- a/mbed.bld	Mon Mar 27 14:29:20 2017 +0000
+++ b/mbed.bld	Wed Apr 21 21:43:07 2021 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file