irrigation system for the ST Nucleo boards

Dependencies:   mbed

Committer:
sheldon_holmes
Date:
Sat Apr 18 21:06:58 2015 +0000
Revision:
4:9e223db481da
2:36,19-4-15

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sheldon_holmes 4:9e223db481da 1 #include "mbed.h"
sheldon_holmes 4:9e223db481da 2 #include "Keepad.h"
sheldon_holmes 4:9e223db481da 3 #include "LCDs.h"
sheldon_holmes 4:9e223db481da 4 //#include "Decoder.h"
sheldon_holmes 4:9e223db481da 5 #include "steps.h"
sheldon_holmes 4:9e223db481da 6 #include "interface.h"
sheldon_holmes 4:9e223db481da 7
sheldon_holmes 4:9e223db481da 8 interface::interface(){}
sheldon_holmes 4:9e223db481da 9
sheldon_holmes 4:9e223db481da 10 void interface::startup()
sheldon_holmes 4:9e223db481da 11 {
sheldon_holmes 4:9e223db481da 12 LCDs lcd;
sheldon_holmes 4:9e223db481da 13 lcd.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 14 lcd.putString(" IRRIGATION SYSTEM STARTED");
sheldon_holmes 4:9e223db481da 15 wait_ms(2000);
sheldon_holmes 4:9e223db481da 16 lcd.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 17 }
sheldon_holmes 4:9e223db481da 18
sheldon_holmes 4:9e223db481da 19 char interface::scr1cnt()
sheldon_holmes 4:9e223db481da 20 {
sheldon_holmes 4:9e223db481da 21 int k1=0;
sheldon_holmes 4:9e223db481da 22 char at = 'z';
sheldon_holmes 4:9e223db481da 23 screen1();
sheldon_holmes 4:9e223db481da 24 steps s;
sheldon_holmes 4:9e223db481da 25 while(k1!=11 && k1!=21 && k1!=31)
sheldon_holmes 4:9e223db481da 26 {
sheldon_holmes 4:9e223db481da 27 k1 = keyInp();
sheldon_holmes 4:9e223db481da 28 }
sheldon_holmes 4:9e223db481da 29 int r = s.step1(k1);
sheldon_holmes 4:9e223db481da 30 k1=0;
sheldon_holmes 4:9e223db481da 31 while(k1==0)
sheldon_holmes 4:9e223db481da 32 {
sheldon_holmes 4:9e223db481da 33 k1 = keyInp();
sheldon_holmes 4:9e223db481da 34 if( k1 == 33)
sheldon_holmes 4:9e223db481da 35 screen1();
sheldon_holmes 4:9e223db481da 36 else if( k1 == 21 && r==1)
sheldon_holmes 4:9e223db481da 37 screenManual();
sheldon_holmes 4:9e223db481da 38 else if( k1 == 11 && r==1)
sheldon_holmes 4:9e223db481da 39 {
sheldon_holmes 4:9e223db481da 40 at = screenAuto();
sheldon_holmes 4:9e223db481da 41 if(at=='s')
sheldon_holmes 4:9e223db481da 42 scr1cnt();
sheldon_holmes 4:9e223db481da 43 }
sheldon_holmes 4:9e223db481da 44 else
sheldon_holmes 4:9e223db481da 45 k1=0;
sheldon_holmes 4:9e223db481da 46 }
sheldon_holmes 4:9e223db481da 47 return(at);
sheldon_holmes 4:9e223db481da 48 }
sheldon_holmes 4:9e223db481da 49
sheldon_holmes 4:9e223db481da 50 void interface::screen1()
sheldon_holmes 4:9e223db481da 51 {
sheldon_holmes 4:9e223db481da 52 LCDs lcd2;
sheldon_holmes 4:9e223db481da 53 lcd2.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 54 lcd2.putString("PRESS: 1->MODES 2->TEMP 3->MOIST");
sheldon_holmes 4:9e223db481da 55 }
sheldon_holmes 4:9e223db481da 56
sheldon_holmes 4:9e223db481da 57 void interface::screenManual()
sheldon_holmes 4:9e223db481da 58 {
sheldon_holmes 4:9e223db481da 59 int k4=0;
sheldon_holmes 4:9e223db481da 60 LCDs lcd3;
sheldon_holmes 4:9e223db481da 61 lcd3.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 62 lcd3.putString("Enter Irrigationtime (min): >>>");
sheldon_holmes 4:9e223db481da 63 while( k4 != 41)
sheldon_holmes 4:9e223db481da 64 {
sheldon_holmes 4:9e223db481da 65 k4 = keyInp();
sheldon_holmes 4:9e223db481da 66 if(k4==34)
sheldon_holmes 4:9e223db481da 67 scr1cnt();
sheldon_holmes 4:9e223db481da 68 }
sheldon_holmes 4:9e223db481da 69 lcd3.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 70 string k3 = convNum();
sheldon_holmes 4:9e223db481da 71 lcd3.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 72 lcd3.putString(k3);
sheldon_holmes 4:9e223db481da 73 }
sheldon_holmes 4:9e223db481da 74
sheldon_holmes 4:9e223db481da 75 int interface::screenAuto()
sheldon_holmes 4:9e223db481da 76 {
sheldon_holmes 4:9e223db481da 77 int k3=0;
sheldon_holmes 4:9e223db481da 78 LCDs lcd4;
sheldon_holmes 4:9e223db481da 79 lcd4.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 80 lcd4.putString("Enter crop :");
sheldon_holmes 4:9e223db481da 81 lcd4.lcdcmd(0xC0);
sheldon_holmes 4:9e223db481da 82 lcd4.putString(">Press Right Key");
sheldon_holmes 4:9e223db481da 83 while( k3 != 41)
sheldon_holmes 4:9e223db481da 84 {
sheldon_holmes 4:9e223db481da 85 k3 = keyInp();
sheldon_holmes 4:9e223db481da 86 if(k3==34)
sheldon_holmes 4:9e223db481da 87 scr1cnt();
sheldon_holmes 4:9e223db481da 88 }
sheldon_holmes 4:9e223db481da 89 lcd4.lcdcmd(0x01);
sheldon_holmes 4:9e223db481da 90 lcd4.putString("1.Wheat 2.Maize");
sheldon_holmes 4:9e223db481da 91 lcd4.lcdcmd(0xC0);
sheldon_holmes 4:9e223db481da 92 lcd4.putString("3.Onion 4.Potato");
sheldon_holmes 4:9e223db481da 93 k3=0;
sheldon_holmes 4:9e223db481da 94 while(k3==0)
sheldon_holmes 4:9e223db481da 95 {
sheldon_holmes 4:9e223db481da 96 k3 = keyInp();
sheldon_holmes 4:9e223db481da 97 if( k3 == 11)
sheldon_holmes 4:9e223db481da 98 {
sheldon_holmes 4:9e223db481da 99 //Wheat();
sheldon_holmes 4:9e223db481da 100 return('w');
sheldon_holmes 4:9e223db481da 101 }
sheldon_holmes 4:9e223db481da 102 else if( k3 == 21)
sheldon_holmes 4:9e223db481da 103 {
sheldon_holmes 4:9e223db481da 104 //Maize();
sheldon_holmes 4:9e223db481da 105 return('m');
sheldon_holmes 4:9e223db481da 106 }
sheldon_holmes 4:9e223db481da 107 else if( k3 == 31)
sheldon_holmes 4:9e223db481da 108 {
sheldon_holmes 4:9e223db481da 109 //Onion();
sheldon_holmes 4:9e223db481da 110 return('o');
sheldon_holmes 4:9e223db481da 111 }
sheldon_holmes 4:9e223db481da 112 else if( k3 == 12)
sheldon_holmes 4:9e223db481da 113 {
sheldon_holmes 4:9e223db481da 114 //Potato();
sheldon_holmes 4:9e223db481da 115 return('p');
sheldon_holmes 4:9e223db481da 116 }
sheldon_holmes 4:9e223db481da 117 else if( k3 == 34)
sheldon_holmes 4:9e223db481da 118 return('s');
sheldon_holmes 4:9e223db481da 119 else
sheldon_holmes 4:9e223db481da 120 k3=0;
sheldon_holmes 4:9e223db481da 121 }
sheldon_holmes 4:9e223db481da 122 return('z');
sheldon_holmes 4:9e223db481da 123 }
sheldon_holmes 4:9e223db481da 124
sheldon_holmes 4:9e223db481da 125 int interface::keyInp()
sheldon_holmes 4:9e223db481da 126 {
sheldon_holmes 4:9e223db481da 127 int kp=0;
sheldon_holmes 4:9e223db481da 128 Keepad kpd;
sheldon_holmes 4:9e223db481da 129 while(kp==0){
sheldon_holmes 4:9e223db481da 130 kp=0;
sheldon_holmes 4:9e223db481da 131 kp=kpd.keypad();
sheldon_holmes 4:9e223db481da 132 }
sheldon_holmes 4:9e223db481da 133 return(kp);
sheldon_holmes 4:9e223db481da 134 }
sheldon_holmes 4:9e223db481da 135
sheldon_holmes 4:9e223db481da 136 string interface::convNum()
sheldon_holmes 4:9e223db481da 137 {
sheldon_holmes 4:9e223db481da 138 int cv[10];
sheldon_holmes 4:9e223db481da 139 int i = 0, j = 0, sum = 0;
sheldon_holmes 4:9e223db481da 140 while(j != 34)
sheldon_holmes 4:9e223db481da 141 {
sheldon_holmes 4:9e223db481da 142 j = keyInp();
sheldon_holmes 4:9e223db481da 143 switch(j)
sheldon_holmes 4:9e223db481da 144 {
sheldon_holmes 4:9e223db481da 145 case 11:
sheldon_holmes 4:9e223db481da 146 cv[i] = 1;
sheldon_holmes 4:9e223db481da 147 break;
sheldon_holmes 4:9e223db481da 148 case 21:
sheldon_holmes 4:9e223db481da 149 cv[i] = 2;
sheldon_holmes 4:9e223db481da 150 break;
sheldon_holmes 4:9e223db481da 151 case 31:
sheldon_holmes 4:9e223db481da 152 cv[i] = 3;
sheldon_holmes 4:9e223db481da 153 break;
sheldon_holmes 4:9e223db481da 154 case 12:
sheldon_holmes 4:9e223db481da 155 cv[i] = 4;
sheldon_holmes 4:9e223db481da 156 break;
sheldon_holmes 4:9e223db481da 157 case 22:
sheldon_holmes 4:9e223db481da 158 cv[i] = 5;
sheldon_holmes 4:9e223db481da 159 break;
sheldon_holmes 4:9e223db481da 160 case 32:
sheldon_holmes 4:9e223db481da 161 cv[i] = 6;
sheldon_holmes 4:9e223db481da 162 break;
sheldon_holmes 4:9e223db481da 163 case 13:
sheldon_holmes 4:9e223db481da 164 cv[i] = 7;
sheldon_holmes 4:9e223db481da 165 break;
sheldon_holmes 4:9e223db481da 166 case 23:
sheldon_holmes 4:9e223db481da 167 cv[i] = 8;
sheldon_holmes 4:9e223db481da 168 break;
sheldon_holmes 4:9e223db481da 169 case 24:
sheldon_holmes 4:9e223db481da 170 cv[i] = 9;
sheldon_holmes 4:9e223db481da 171 break;
sheldon_holmes 4:9e223db481da 172 case 14:
sheldon_holmes 4:9e223db481da 173 cv[i] = 0;
sheldon_holmes 4:9e223db481da 174 break;
sheldon_holmes 4:9e223db481da 175 default:
sheldon_holmes 4:9e223db481da 176 break;
sheldon_holmes 4:9e223db481da 177 }
sheldon_holmes 4:9e223db481da 178 i++;
sheldon_holmes 4:9e223db481da 179 }
sheldon_holmes 4:9e223db481da 180 j=1;
sheldon_holmes 4:9e223db481da 181 i=i-2;
sheldon_holmes 4:9e223db481da 182 sum = cv[i];
sheldon_holmes 4:9e223db481da 183 for(int t = 1; t <= i; t++)
sheldon_holmes 4:9e223db481da 184 {
sheldon_holmes 4:9e223db481da 185 j=j*10;
sheldon_holmes 4:9e223db481da 186 }
sheldon_holmes 4:9e223db481da 187
sheldon_holmes 4:9e223db481da 188 for(int tv = 0; tv <i; tv++)
sheldon_holmes 4:9e223db481da 189 {
sheldon_holmes 4:9e223db481da 190 sum = sum + (cv[tv]*j);
sheldon_holmes 4:9e223db481da 191 j=j/10;
sheldon_holmes 4:9e223db481da 192 }
sheldon_holmes 4:9e223db481da 193
sheldon_holmes 4:9e223db481da 194 char dis[16];
sheldon_holmes 4:9e223db481da 195 sprintf(dis,"%d",sum);
sheldon_holmes 4:9e223db481da 196 return(dis);
sheldon_holmes 4:9e223db481da 197 }