Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:9e223db481da, committed 2015-04-18
- Comitter:
 - sheldon_holmes
 - Date:
 - Sat Apr 18 21:06:58 2015 +0000
 - Parent:
 - 3:f57d754b1814
 - Commit message:
 - 2:36,19-4-15
 
Changed in this revision
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Decoder.cpp	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+#include "Decoder.h"
+
+DigitalIn dec0(PB_7);
+DigitalIn dec1(PA_15);
+DigitalIn dec2(PA_14);
+DigitalIn dec3(PA_13);
+
+int gb = 0;
+
+Decoder::Decoder()
+{}
+
+int Decoder::checkIn()
+{
+    int d = 0;
+    if(dec0==1)
+    {
+        d=d+1;
+    }
+    if(dec1==1)
+    {
+        d=d+2;
+    }
+    if(dec2==1)
+    {
+        d=d+4;
+    }
+    if(dec3==1)
+    {
+        d=d+8;
+    }
+    return(d);
+}
+
+void Decoder::control(){
+    int rc = checkIn();
+    if(rc==15)
+    {
+        
+    }
+    if(rc==14)
+    {
+        
+    }
+    if(rc==13)
+    {
+        
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Decoder.h	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,11 @@
+#ifndef Decoder_H
+#define Decoder_H
+#include "mbed.h"
+
+class Decoder{
+    public:
+    Decoder();
+    int checkIn();
+    void control();
+}; 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keepad.cpp	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,114 @@
+#include "mbed.h"
+#include "Keepad.h"
+#include "LCDs.h"
+
+DigitalIn bi1(PC_8);
+DigitalIn bi2(PC_6);
+DigitalIn bi3(PC_5);
+DigitalIn bi4(PB_1);
+DigitalOut bo1(PA_12);
+DigitalOut bo2(PA_11);
+DigitalOut bo3(PB_12);
+DigitalOut bo4(PB_11);
+
+int g = 0;
+
+Keepad::Keepad(){}
+
+int Keepad::keypad()
+{   
+    g=7;
+   LCDs t2;
+   //t2.lcdcmd(0x01);
+   wait_ms(10);   
+   g=5;
+   int i=0;
+   
+   bo1 = 1;
+   bo2 = 0;
+   bo3 = 0;
+   bo4 = 0;
+   keypadIn();   
+   if(g!=5)
+   {
+    t2.putString("A");
+    i=10+g;
+    wait_ms(500);
+    return(i);
+   }
+   
+   bo1 = 0;
+   bo2 = 1;
+   bo3 = 0;
+   bo4 = 0;
+   keypadIn();
+   if(g!=5)
+   {
+    t2.putString("B");
+    i=20+g;
+    wait_ms(500);
+    return(i);
+   }
+   
+   bo1 = 0;
+   bo2 = 0;
+   bo3 = 1;
+   bo4 = 0;
+   keypadIn();
+   if(g!=5)
+   {
+    t2.putString("C");
+    i=30+g;
+    wait_ms(500);
+    return(i);
+   }
+   
+   bo1 = 0;
+   bo2 = 0;
+   bo3 = 0;
+   bo4 = 1;
+   keypadIn();
+   if(g!=5)
+   {
+    t2.putString("D");
+    i=40+g;
+    wait_ms(500);
+    return(i);
+   }   
+   return(0);
+}
+
+void Keepad::keypadIn()
+{    
+    LCDs t3;
+    for(int l=1;l<10;l++)
+    {
+    if(bi1 == 1)
+    {
+        t3.putString("1");
+        g=1;
+        break;
+    }
+    else if(bi2 == 1)
+    {
+        t3.putString("2");
+        g=2;
+        break;
+    }
+    else if(bi3 == 1)
+    {
+        t3.putString("3");
+        g=3;
+        break;
+    }
+    else if(bi4 == 1)
+    {
+        t3.putString("4");
+        g=4;
+        break;
+    }
+    else
+    {g=5;}
+    wait_ms(10);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keepad.h	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,11 @@
+#ifndef KEEPAD_H
+#define KEEPAD_H
+#include "mbed.h"
+
+class Keepad{
+    public:
+    Keepad();
+    int keypad();
+    void keypadIn();
+}; 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCDs.cpp	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "LCDs.h"
+#include <string>
+
+DigitalOut rs(PA_6);
+DigitalOut en(PB_6);
+DigitalOut rw(PA_7);
+DigitalOut db0(PC_7);
+DigitalOut db1(PA_9);
+DigitalOut db2(PA_8);
+DigitalOut db3(PB_10);
+DigitalOut db4(PB_4);
+DigitalOut db5(PB_5);
+DigitalOut db6(PB_3);
+DigitalInOut db7(PA_10);
+
+LCDs::LCDs()
+{}
+
+void LCDs::lcdinit()
+{
+    db7.output();
+    db7=0;    
+    en=0;
+    wait_ms(250);
+}
+
+void LCDs::putString(string disp)
+{
+    for(int j = 0; j < disp.length(); j++)
+    {
+        if(j==16)
+            lcdcmd(0xC0);
+        putData((unsigned char)disp.at(j));
+        rs=1;
+        rw=0;
+        en=1;
+        wait_ms(1);
+        en=0;
+        lcdReady();
+    }
+}
+
+void LCDs::lcdReady()
+{
+    db7.input();
+    rs=0;
+    rw=1;
+    do
+    {
+        en=1;
+        wait_ms(1);
+        en=0;
+    }while(db7==1);
+    db7.output();
+}
+
+void LCDs::putData(unsigned char value)
+{
+    unsigned char newValue = value;
+    for(int i = 0; i<=7; i++)
+    {    
+        newValue = value>>i;       
+        newValue = newValue & 0x01;
+        switch(i)
+        {
+            case 0:
+               db0=(int)newValue;
+               break;
+            case 1:
+               db1=(int)newValue;
+               break;
+            case 2:
+               db2=(int)newValue;
+               break;
+            case 3:
+               db3=(int)newValue;
+               break;
+            case 4:
+               db4=(int)newValue;
+               break;
+            case 5:
+               db5=(int)newValue;
+               break;
+            case 6:
+               db6=(int)newValue;
+               break;
+            case 7:
+               db7=(int)newValue;
+               break;
+            default:
+                break;
+        }         
+    }
+}
+
+void LCDs::lcdcmd(unsigned char value)
+{
+    putData(value);
+    rs=0;
+    rw=0;
+    en=1;
+    wait_ms(1);
+    en=0;
+    lcdReady();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCDs.h	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,15 @@
+#ifndef LCDs_H
+#define LCDs_H
+#include "mbed.h"
+#include <string>
+
+class LCDs{
+    public:
+    LCDs();
+    void lcdinit();
+    void putString(string);
+    void lcdReady();
+    void putData(unsigned char);
+    void lcdcmd(unsigned char);
+}; 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/interface.cpp	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,197 @@
+#include "mbed.h"
+#include "Keepad.h"
+#include "LCDs.h"
+//#include "Decoder.h"
+#include "steps.h"
+#include "interface.h"
+
+interface::interface(){}
+
+void interface::startup()
+{
+    LCDs lcd;    
+    lcd.lcdcmd(0x01);  
+    lcd.putString("   IRRIGATION    SYSTEM STARTED");
+    wait_ms(2000);
+    lcd.lcdcmd(0x01);  
+}
+
+char interface::scr1cnt()
+{   
+    int k1=0;
+    char at = 'z';
+    screen1();
+    steps s;
+    while(k1!=11 && k1!=21 && k1!=31)
+    {
+        k1 = keyInp();
+    }
+    int r = s.step1(k1);
+    k1=0;
+    while(k1==0)
+    {
+        k1 = keyInp();
+        if( k1 == 33)
+            screen1();
+        else if( k1 == 21 && r==1)
+            screenManual();
+        else if( k1 == 11 && r==1)
+        {
+            at = screenAuto();
+            if(at=='s')
+                scr1cnt();
+        }
+        else
+            k1=0;
+    }
+    return(at);
+}
+
+void interface::screen1()
+{
+    LCDs lcd2;
+    lcd2.lcdcmd(0x01);
+    lcd2.putString("PRESS: 1->MODES 2->TEMP 3->MOIST");    
+}
+
+void interface::screenManual()
+{
+    int k4=0;
+    LCDs lcd3;
+    lcd3.lcdcmd(0x01);
+    lcd3.putString("Enter Irrigationtime (min): >>>");
+    while( k4 != 41)
+    {
+        k4 = keyInp();
+        if(k4==34)
+            scr1cnt();
+    }
+    lcd3.lcdcmd(0x01);
+    string k3 = convNum();
+    lcd3.lcdcmd(0x01);
+    lcd3.putString(k3);
+}
+
+int interface::screenAuto()
+{
+    int k3=0;
+    LCDs lcd4;
+    lcd4.lcdcmd(0x01);
+    lcd4.putString("Enter crop :");
+    lcd4.lcdcmd(0xC0);
+    lcd4.putString(">Press Right Key");        
+    while( k3 != 41)
+    {
+        k3 = keyInp();
+        if(k3==34)
+            scr1cnt();
+    }
+    lcd4.lcdcmd(0x01);
+    lcd4.putString("1.Wheat  2.Maize");
+    lcd4.lcdcmd(0xC0);
+    lcd4.putString("3.Onion 4.Potato");
+    k3=0;
+    while(k3==0)
+    {
+        k3 = keyInp();
+        if( k3 == 11)
+        {
+            //Wheat();
+            return('w');
+        }
+        else if( k3 == 21)
+        {
+            //Maize();
+            return('m');
+        }
+        else if( k3 == 31)
+        {
+            //Onion();
+            return('o');
+        }
+        else if( k3 == 12)
+        {
+            //Potato();
+            return('p');
+        }
+        else if( k3 == 34)        
+            return('s');
+        else
+            k3=0;
+    }
+    return('z');
+}
+
+int interface::keyInp()
+{
+    int kp=0;
+    Keepad kpd;
+    while(kp==0){
+        kp=0;
+        kp=kpd.keypad();
+    }
+    return(kp);
+}
+
+string interface::convNum()
+{
+    int cv[10];
+    int i = 0, j = 0, sum = 0;    
+    while(j != 34)
+    {
+        j = keyInp();        
+        switch(j)
+        {
+            case 11:
+                cv[i] = 1;
+                break;
+            case 21:
+                cv[i] = 2;
+                break;
+            case 31:
+                cv[i] = 3;
+                break;
+            case 12:
+                cv[i] = 4;
+                break;
+            case 22:
+                cv[i] = 5;
+                break;
+            case 32:
+                cv[i] = 6;
+                break;
+            case 13:
+                cv[i] = 7;
+                break;
+            case 23:
+                cv[i] = 8;
+                break;
+            case 24:
+                cv[i] = 9;
+                break;
+            case 14:
+                cv[i] = 0;
+                break;
+            default:
+                break;
+        }
+        i++;
+    }
+    j=1;
+    i=i-2;
+    sum = cv[i];
+    for(int t = 1; t <= i; t++)
+    {
+        j=j*10;
+    }
+    
+    for(int tv = 0; tv <i; tv++)
+    {
+        sum = sum + (cv[tv]*j);
+        j=j/10;
+    }
+    
+    char dis[16];
+    sprintf(dis,"%d",sum);
+    return(dis);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/interface.h	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,16 @@
+#ifndef interface_H
+#define interface_H
+#include "mbed.h"
+
+class interface{
+    public:
+        interface(); 
+        void startup();
+        char scr1cnt();
+        void screen1();
+        void screenManual();
+        int screenAuto();
+        int keyInp();
+        string convNum();
+}; 
+#endif
\ No newline at end of file
--- a/main.cpp	Thu Nov 06 10:13:20 2014 +0000
+++ b/main.cpp	Sat Apr 18 21:06:58 2015 +0000
@@ -1,12 +1,29 @@
 #include "mbed.h"
+#include <string>
+#include "Keepad.h"
+#include "LCDs.h"
+#include "Decoder.h"
+//#include "steps.h"
+#include "interface.h"
 
-DigitalOut myled(LED1);
+DigitalOut led1(PC_13);
+DigitalOut led2(PC_14);
+DigitalOut led3(PC_15);
+
+DigitalOut relay(PC_3);
 
-int main() {
-    while(1) {
-        myled = 1; // LED is ON
-        wait(0.2); // 200 ms
-        myled = 0; // LED is OFF
-        wait(1.0); // 1 sec
-    }
-}
+DigitalOut led(LED1);
+
+int main(){       
+    char at = 'z';
+    //steps s;        
+    LCDs c;
+    c.lcdinit();    
+    interface inf;    
+    c.lcdcmd(0x38);
+    wait_ms(250);
+    c.lcdcmd(0x0C);    
+    inf.startup();
+    at = inf.scr1cnt();
+    led=1;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/steps.cpp	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+#include "steps.h"
+#include "LCDs.h"
+#include "Decoder.h"
+
+steps::steps(){}
+
+int steps::step1(int v)
+{
+    LCDs c;
+    Decoder d;
+    if(v==11){
+        c.lcdcmd(0x01);
+        c.putString("1-> AUTOMATIC   2-> MANUAL");
+        return(1);
+    }
+    
+    else if(v==21){        
+        char disp[16];
+        int temp = d.checkIn();
+        sprintf(disp,"%d",temp*5);        
+        c.lcdcmd(0x01);
+        c.putString("temperature: ");
+        c.lcdcmd(0xC0);
+        c.putString(disp);
+        c.putString(" C");   
+        return(2);     
+    }
+    
+    else if(v==31){
+        char disp2[16];
+        int temp2 = d.checkIn();
+        sprintf(disp2,"%d",temp2*8);        
+        c.lcdcmd(0x01);
+        c.putString("Soil Moisture: ");
+        c.lcdcmd(0xC0);
+        c.putString(disp2);
+        c.putString(" %");
+        return(3);
+    }
+    else
+    {
+        return(0);
+    }
+}
+
+void steps::automatic(int v2)
+{
+    
+}
+
+void steps::manual(int v2)
+{
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/steps.h	Sat Apr 18 21:06:58 2015 +0000
@@ -0,0 +1,12 @@
+#ifndef steps_H
+#define steps_H
+#include "mbed.h"
+
+class steps{
+    public:
+        steps();
+        int step1(int);
+        void automatic(int);
+        void manual(int);
+}; 
+#endif
\ No newline at end of file