current code

Dependencies:   mbed Motor TextLCD Keypad Frdmlz25 DHT11

Dependents:   Frdmlz25

Branch:
All_done_withoutWIFI
Revision:
6:05022e3201ac
Parent:
2:8ed2269ab264
Child:
7:da7c96261a91
--- a/main.cpp	Thu Nov 08 17:26:25 2018 +0000
+++ b/main.cpp	Mon Nov 12 18:42:13 2018 +0000
@@ -3,9 +3,10 @@
 #include "TSL2561.h"
 #include "Keypad.h"
 #include "TextLCD.h"
+#include "Motor.h"
 
 //Setup a new plant1 data
-float p1_tMin=35.0, p1_tMax=45.0;
+float p1_tMin=10.0, p1_tMax=19.0;
 float p1_lMin=300.0, p1_lMax=50000.0;
 float p1_hMin=60.0, p1_hMax=70.0;
 //Setup a new plant2 data
@@ -17,27 +18,31 @@
 float p3_lMin=100.0, p3_lMax=50000.0;
 float p3_hMin=30.0, p3_hMax=70.0;
 
-Serial PC(PTE0, PTE1);
-#define PC_PRINTX(z,x)             if(z==1) PC.printf(x);
-#define PC_PRINTLNX(z,x)           if(z==1) {PC.printf(x);        PC.printf("\r\n");}
-#define PC_PRINTXY(z,x, y)         if(z==1) PC.printf(x, y);
-#define PC_PRINTLNXY(z,x, y)       if(z==1) {PC.printf(x, y);     PC.printf("\r\n");}
+Serial pc(PTE0,PTE1);
+#define _PRINTX(z,x)             if(z==1) .printf(x);
+#define _PRINTLNX(z,x)           if(z==1) {.printf(x);        .printf("\r\n");}
+#define _PRINTXY(z,x, y)         if(z==1) .printf(x, y);
+#define _PRINTLNXY(z,x, y)       if(z==1) {.printf(x, y);     .printf("\r\n");}
  
 
 //Setup a new plant data
 
 Dht11 sensor(PTB0);
 TSL2561 tsl2561(TSL2561_ADDR_FLOAT);// Use the tsl2561 sensor
-
+Motor m(PTD2,PTC17,PTC16);//water motor
+Motor w(PTD0,PTC13,PTC12);//wind motor
 
 //Setup output
-DigitalOut output1(PTD3);  //Setup output
-DigitalOut output2(PTD2);  //Setup output
-DigitalOut output3(PTE5);  //Setup output
+DigitalOut output1(PTD3);  //lighting
+DigitalOut m1(PTC13);  //Setup water motor output forward
+DigitalOut m2(PTC12);  //Setup water motor output backword
+DigitalOut w1(PTC17);  //Setup wind motor output forward
+DigitalOut w2(PTC16);  //Setup wind motor output backword
+
 DigitalOut output4(PTD5);  //Setup output
 Keypad KeyInput(PTC4,PTC3,PTC0,PTC7,PTC11,PTC10,PTC6,PTC5);
 TextLCD lcd(PTB8,PTB9,PTB10,PTB11,PTE2,PTE3,TextLCD::LCD16x2);
-//float output1=0,output2=0,output3=0,output4=0;// lighting// ventilation// watering// heating
+//float output1=0,w.speed(0),m.speed(0),output4=0;// lighting// watering// ventilation// heating
 
          
                                       
@@ -47,7 +52,12 @@
     char keym,tempkey;
     uint16_t val_lig;
     float val_tmp,t;  
-//    int output1,output2,output3,output4;
+    m1=1;
+    m2=0;
+    w1=1;
+    w2=0;
+    
+//    int output1,output2,m.speed,output4;
     
     
     lcd.printf("-----START------");
@@ -100,21 +110,21 @@
                     lcd.cls();
                     
                     // compare data
-                    lcd.printf("key is:%c \n",keym); 
-                    wait(2);
+                    //lcd.printf("key is:%c \n",keym); 
+                    //wait(2);
                     if (keym=='1') {
                         if (val_tmp>=p1_tMin && val_tmp<=p1_tMax)   {
                             if (val_hud>=p1_hMin && val_hud<=p1_hMax) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -123,28 +133,28 @@
                             else if (val_hud<=p1_hMin ) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0.3);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
                             else    {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(1);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.4);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -155,14 +165,14 @@
                             if (val_hud>=p1_hMin && val_hud<=p1_hMax){
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 }
@@ -170,28 +180,28 @@
                             else if (val_hud<=p1_hMin ) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=1;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=1;
                                     }
                                 }
                             else    {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 }
@@ -203,14 +213,14 @@
                             if (val_hud>=p1_hMin && val_hud<=p1_hMax){
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.8);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.4);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
@@ -218,28 +228,28 @@
                             else if (val_hud<=p1_hMin ) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.3);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
                             else{
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(1);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(1);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -252,14 +262,14 @@
                             if (val_hud>=p2_hMin && val_hud<=p2_hMax) {
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<p2_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -268,28 +278,28 @@
                             else if (val_hud<=p2_hMin ) {
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<p2_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
                             else    {
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -300,14 +310,14 @@
                             if (val_hud>=p2_hMin && val_hud<=p2_hMax){
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 else if (val_lig<=p2_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 }
@@ -315,28 +325,28 @@
                             else if (val_hud<=p2_hMin ) {
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=1;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=1;
                                     }
                                 }
                             else    {
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 else if (val_lig<=p2_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 }
@@ -348,14 +358,14 @@
                             if (val_hud>=p2_hMin && val_hud<=p2_hMax){
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<=p2_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
@@ -363,28 +373,28 @@
                             else if (val_hud<=p2_hMin ) {
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<=p2_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
                             else{
                                 if (val_lig>=p2_lMin && val_lig<=p2_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<=p2_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -396,14 +406,14 @@
                             if (val_hud>=p1_hMin && val_hud<=p1_hMax) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -412,28 +422,28 @@
                             else if (val_hud<=p1_hMin ) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
                             else    {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }
@@ -444,14 +454,14 @@
                             if (val_hud>=p1_hMin && val_hud<=p1_hMax){
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=0;
+                                    w.speed(0);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 }
@@ -459,28 +469,28 @@
                             else if (val_hud<=p1_hMin ) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=1;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=0;
-                                    output3=1;
+                                    w.speed(0);
+                                    m.speed(1);
                                     output4=1;
                                     }
                                 }
                             else    {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=1;
                                     }
                                 }
@@ -492,14 +502,14 @@
                             if (val_hud>=p1_hMin && val_hud<=p1_hMax){
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
@@ -507,28 +517,28 @@
                             else if (val_hud<=p1_hMin ) {
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=1;
+                                    w.speed(0.5);
+                                    m.speed(1);
                                     output4=0;
                                     }
                                 }
                             else{
                                 if (val_lig>=p1_lMin && val_lig<=p1_lMax) {
                                     output1=0;
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 else if (val_lig<=p1_lMin){
                                     output1=1; 
-                                    output2=1;
-                                    output3=0;
+                                    w.speed(0.5);
+                                    m.speed(0);
                                     output4=0;
                                     }
                                 }