Project aiming to make a self-controlled solar reflector

Dependencies:   Accelerometer LCD Inverter Algorithm MotorDriver Anemometer GUI ArduinoJson Misc Definitions Pushbutton WebSocketClient temp_fan

Revision:
2:944511c6c55f
Parent:
1:07f86b4db069
Child:
6:0b7a6e51cdf8
--- a/main.cpp	Mon Feb 15 21:49:09 2021 +0000
+++ b/main.cpp	Sun Feb 28 03:26:47 2021 +0000
@@ -5,27 +5,29 @@
 
 //INCLUDES
 #include "mbed.h"
+#include "string"     // std::string, std::to_string
 #include "Accelerometer.h"
 #include "Anemometer.h"
 #include "Algorithm.h"
 #include "MotorDriver.h"
 #include "Defs_Sett.h"
 #include "Pushbutton.h"
+#include "LCD.h"
 
 #define timer_read_s(x)     chrono::duration_cast<chrono::seconds>((x).elapsed_time()).count()
 
 //Initialize Global Variables
-Accelerometer acc(40000); //Accelerometer
+Accelerometer acc; //Accelerometer
 Anemometer ane; //
 MotorDriver motor;
+LCD lcd;
 LowPowerTimer t,t_mode;
 Ticker ti;
-int mode = OP_NORMAL;
+int mode = OP_CALLIBRATION;
 
 Pushbutton bt_fn(PIN_BTFN,&mode);
 Pushbutton bt_inc(PIN_BTINC);
 Pushbutton bt_dec(PIN_BTDEC);
-Pushbutton* Pushbutton::LastPressed = &bt_fn;
 
 //Function Declarations
 void checkWind();
@@ -48,6 +50,7 @@
     switch(mode)
     {
         case OP_NORMAL:
+            lcd.LCD_display("NORMAL","");
             if(flag_time) //If delay interval has passed
             {
                 ti.attach(&checkWind,TICK_WIND); //Enable Wind Safety
@@ -90,7 +93,7 @@
                     ang_R = acc.getAngle(S_R2);
                 }
                 motor.stop();
-                flag_time = 0; //Initiate delay
+                flag_time = 0; //Reset timer flag
                 t.reset(); //Reset timer
             }
             t_elapsed = (int)timer_read_s(t);
@@ -98,12 +101,14 @@
             break;
 ////////////////////////////////////////////////////////////////////////////////
         case OP_WIND:
+            lcd.LCD_display("WIND SAFETY","");
             //Move all motor backward
             motor.moveBackward(M_ALL);
             flag_time = 1; //Set the system in motion once windspeed has subsided
             break;
 ////////////////////////////////////////////////////////////////////////////////
         case OP_MANUAL1:
+            lcd.LCD_display("MOTOR 1","");
             ti.detach(); //Disable Wind Safety
             
             //TIMEOUT
@@ -138,6 +143,7 @@
             break;
 ////////////////////////////////////////////////////////////////////////////////
         case OP_MANUAL2:
+            lcd.LCD_display("MOTOR 2","");
             ti.detach(); //Disable Wind Safety
             
             //TIMEOUT
@@ -172,6 +178,7 @@
             break;
 ////////////////////////////////////////////////////////////////////////////////
         case OP_WSETTING:
+            lcd.LCD_display("Threshold:",to_string(wthres));
             motor.stop();
             ti.detach(); //Disable Wind Safety
             
@@ -186,16 +193,19 @@
             else if(timer_read_s(t_mode) > TIME_WSETTING_TIMEOUT)
             {
                 mode = OP_NORMAL;
+                break;
             }
             ////////////////////////////////////////////////////////////////////
             
             if(bt_inc.read() && wthres < WIND_THRES_MAX)
             {
                 ane.setThres(++wthres);
+                lcd.LCD_display("Threshold:",to_string(wthres));
             }
             else if(bt_inc.read() && wthres > WIND_THRES_MIN)
             {
                 ane.setThres(--wthres);
+                lcd.LCD_display("Threshold:",to_string(wthres));
             }
             
             flag_time = 1; //Set the system in motion once done adjusting