Go Down

Topic: Arduino Control Desktop - ACiD (Read 2 times) previous topic - next topic

spycatcher2k

#5
Apr 25, 2010, 03:33 pm Last Edit: Apr 25, 2010, 08:21 pm by spycatcher2k Reason: 1
Code part 2:

Code: [Select]
   
   
  if (level==4)
{
     temp13 = digitalRead(13);
     temp12 = digitalRead(12);
     temp11 = digitalRead(11);
     temp10 = digitalRead(10);
     temp9 = digitalRead(9);
     temp8 = digitalRead(8);
     temp7 = digitalRead(7);
     temp6 = digitalRead(6);
     temp5 = digitalRead(5);
     temp4 = digitalRead(4);
     temp3 = digitalRead(3);
     if (temp13 == 1)
     {
     prts[12]='1';
     }
     else
     {
     prts[12]='0';
     }
     if (temp12 == 1)
     {
     prts[11]='1';
     }
     else
     {
     prts[11]='0';
     }
     if (temp11 == 1)
     {
     prts[10]='1';
     }
     else
     {
     prts[10]='0';
     }
     if (temp10 == 1)
     {
     prts[9]='1';
     }
     else
     {
     prts[9]='0';
     }
     if (temp9 == 1)
     {
     prts[8]='1';
     }
     else
     {
     prts[8]='0';
     }
     if (temp8 == 1)
     {
     prts[7]='1';
     }
     else
     {
     prts[7]='0';
     }
     if (temp7 == 1)
     {
     prts[6]='1';
     }
     else
     {
     prts[6]='0';
     }
     if (temp6 == 1)
     {
     prts[5]='1';
     }
     else
     {
     prts[5]='0';
     }
     if (temp5 == 1)
     {
     prts[4]='1';
     }
     else
     {
     prts[4]='0';
     }
     if (temp4 == 1)
     {
     prts[3]='1';
     }
     else
     {
     prts[3]='0';
     }
     if (temp3 == 1)
     {
     prts[2]='1';
     }
     else
     {
     prts[2]='0';
     }
     delay(10);      
     Serial.println(prts);
     delay(10);
}
if (level==5)
{
 Serial.println("#########################################");
 Serial.println("##                                     ##");
 Serial.println("##       Arduino Control Desktop       ##");
 Serial.println("##                                     ##");
 Serial.println("##              V0.2 Beta              ##");
 Serial.println("##                                     ##");
 Serial.println("##                About                ##");
 Serial.println("##                                     ##");
 Serial.println("#########################################");
 Serial.println(" ");  
 Serial.println("   Very Basic Control Program for the Arduino");
 Serial.println("-=############################################=-");
 Serial.println(" ");
 Serial.println("Feel free to use, update, cut, copy, paste, mutilate");
 Serial.println("or delete this code. Its given to the world totaly");
 Serial.println("without reservation.");
 Serial.println(" ");
 Serial.println("Commands Available :");
 Serial.println("Mxy - pinMode");
 Serial.println("      x=pin number 2-9, 0=10, a=11, b=12, c=13");
 Serial.println("      y=0 for output, y=1 for input");
 Serial.println("R   - Long port status report 0=LOW, 1=High");
 Serial.println("S   - Report port use in binary style");
 Serial.println("P   - Report pinMode in binary style");
 Serial.println("Hx  - Set port HIGH (pins as M)");
 Serial.println("Lx  - Set port LOW (pins as M)");
 Serial.println(" ");
 Serial.println("affix command with x e.g : ");
 Serial.println("xH2  - will set pin 2 HIGH ");
 Serial.println("xLa  - will set pin 11 LOW ");
 Serial.println("xM2i - will set pin 2 to INPUT");
 Serial.println(" ");
}
}
}


Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

spycatcher2k

#6
Apr 25, 2010, 05:40 pm Last Edit: Apr 25, 2010, 08:22 pm by spycatcher2k Reason: 1
Had to edit the above code - It just didn't work properly. Should be OK now.


Spycatcher2k

And again

Still a work on progress though.
Any ideas to enhance this project then leave a reply.

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

cr0sh

#7
Apr 26, 2010, 12:09 am Last Edit: Apr 26, 2010, 12:10 am by keeper63@cox.net Reason: 1
First off, this looks like a very useful project, most likely as a debugging tool - I think it is something that should be submitted to the playground once you have it past the beta stage.

What I would suggest improving, though, is removing the redundant code; you have many areas that could be simplified into singular functions (such as the banner output), as well as where loop constructs or other constructs could be applied. Doing these things would vastly simplify the sketch, and likely reduce its footprint (size) on the Arduino.

:)
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

spycatcher2k

#8
Apr 26, 2010, 01:55 am Last Edit: Apr 26, 2010, 02:01 am by spycatcher2k Reason: 1
Updated - Smaller, and Some logic errors fixed.
Code: [Select]

//
//
//  ACiD V1.0
//
//  Arduino Control Desktop
//
// Drew Anderson - 2010 (24/5/10)
//
// Connect with any com program - I use this as a simple
// In/Out Handler for my VB6 programs - Easy protocol to
// implement.
//
// send x   -  reset to root menu
// send 4   -  Ask for Digital port values 0=LOW 1=HIGH
//
// Then just parse the string to read port value
// (reads ALL ports 2 - 13)
//
// send x   -  reset to root menu
// send 2   -  select WRITE HIGH menu
// send 3->0 or a,b or c   -  select port to set HIGH
//
// send x   -  reset to root menu
// send 3   -  select WRITE LOW menu
// send 3->0 or a,b or c   -  select port to set LOW



int level=0;
int tmp1=0;
int sinput=0;


void bannertop()
{
 Serial.println("#########################################");
 Serial.println("##                                     ##");
 Serial.println("##       Arduino Control Desktop       ##");
 Serial.println("##                                     ##");
 Serial.println("##              V0.1 Beta              ##");
 Serial.println("##                                     ##");
}
void bannerbase()
{
 Serial.println("##                                     ##");
 Serial.println("#########################################");
 Serial.println(" ");
}
void bannerinst()
{  Serial.println(" ");
 Serial.println("Enter 2-9, for ports 2 -> 9");
 Serial.println("or 0 for 10 - a for 11 - b for 12");
 Serial.println("or finaly c for 13");
 Serial.println(" ");
 Serial.println("x. Back to main Screen");
 Serial.println(" ");
}
 void setup()
{
 Serial.begin(57600);
 bannertop();
 bannerbase();
 Serial.println(" ");
 Serial.println("1. Report Port Status (Digital Only)");
 Serial.println("2. Set port to high");
 Serial.println("3. Set port to low");
 Serial.println("4. Binary string report");
 Serial.println("5. About");
 Serial.println(" ");

 int x=0;
 for(x=2;x<14;x++)
 {
   pinMode(x, OUTPUT);
 }
//
// If you need to set any port to input then do it here
//

// pinMode(2, INPUT);
// pinMode(3, INPUT);
// pinMode(4, INPUT);
// pinMode(5, INPUT);
// pinMode(6, INPUT);
// pinMode(7, INPUT);
// pinMode(8, INPUT);
// pinMode(9, INPUT);
// pinMode(10, INPUT);
// pinMode(11, INPUT);
// pinMode(12, INPUT);
// pinMode(13, INPUT);
}

void loop()
{
 
 if (Serial.available() > 0)
 {
   sinput = Serial.read();
   // x - Reset to start Screen
   if (sinput=='x')
   {
     level=0;
   }
   
   // Level 0 - 1 - 4 Choose from root menu
   if (level==0)
   {
       if (sinput=='1')
   {
     level=1;
   }  
       if (sinput=='2')
   {
     level=2;
   }
       if (sinput=='3')
   {
     level=3;
   }
       if (sinput=='4')
   {
     level=4;
   }
   }
   // Level 2 - 3-9 Zero, and a,b or c  Select port to update HIGH
   
   if(level==2)
   {
   
           if (sinput=='2')
   {
     digitalWrite(2, HIGH);
   }
           if (sinput=='3')
   {
     digitalWrite(3, HIGH);
   }
           if (sinput=='4')
   {
     digitalWrite(4, HIGH);
   }
           if (sinput=='5')
   {
     digitalWrite(5, HIGH);
   }
           if (sinput=='6')
   {
     digitalWrite(6, HIGH);
   }
           if (sinput=='7')
   {
     digitalWrite(7, HIGH);
   }
           if (sinput=='8')
   {
     digitalWrite(8, HIGH);
   }
           if (sinput=='9')
   {
     digitalWrite(9, HIGH);
   }
           if (sinput=='0')
   {
     digitalWrite(10, HIGH);
   }
           if (sinput=='a')
   {
     digitalWrite(11, HIGH);
   }
           if (sinput=='b')
   {
     digitalWrite(12, HIGH);
   }
           if (sinput=='c')
   {
     digitalWrite(13, HIGH);
   }
   }
   
   // Level 2 - 3-9 Zero, and a,b or c  Select port to update LOW
   
    if(level==3);
    {
           if (sinput=='2')
   {
     digitalWrite(2, LOW);
   }
           if (sinput=='3')
   {
     digitalWrite(3, LOW);
   }
           if (sinput=='4')
   {
     digitalWrite(4, LOW);
   }
           if (sinput=='5')
   {
     digitalWrite(5, LOW);
   }
           if (sinput=='6')
   {
     digitalWrite(6, LOW);
   }
           if (sinput=='7')
   {
     digitalWrite(7, LOW);
   }
           if (sinput=='8')
   {
     digitalWrite(8, LOW);
   }
           if (sinput=='9')
   {
     digitalWrite(9, LOW);
   }
           if (sinput=='0')
   {
     digitalWrite(10, LOW);
   }
           if (sinput=='a')
   {
     digitalWrite(11, LOW);
   }
           if (sinput=='b')
   {
     digitalWrite(12, LOW);
   }
           if (sinput=='c')
   {
     digitalWrite(13, LOW);
   }
    }
   
//Lets print the menus to the serial port    
   
if (level==0)
{
 bannertop();
 bannerbase();
 Serial.println("1. Report Port Status (Digital Only)");
 Serial.println("2. Set port to high");
 Serial.println("3. Set port to low");
 Serial.println("4. Binary string report");
 Serial.println(" ");
}
if(level==1)
{
 bannertop();
 Serial.println("##         Digital port status         ##");
 bannerbase();
 for(tmp1=2;tmp1<14;tmp1++)
 {
 if (digitalRead(tmp1)==1)
 {
   Serial.print("Pin ");
   if(tmp1<10)
   {
     Serial.print("0");
   }
  Serial.print(tmp1);
 Serial.println(" is currently High.");
 }
 else
 {
   Serial.print("Pin ");
      if(tmp1<10)
   {
     Serial.print("0");
   }
   Serial.print(tmp1);
   Serial.println(" is currently Low.");
 }
 }
 Serial.println(" ");
 Serial.println("x. Return to First Screen");
}
if (level==2)
{
 bannertop();
 Serial.println("##         Digital port update         ##");
 Serial.println("##                                     ##");
 Serial.println("##            SET PORT HIGH            ##");
 bannerbase();
 bannerinst();
}
if (level==3)
{
 bannertop();
 Serial.println("##         Digital port update         ##");
 Serial.println("##                                     ##");
 Serial.println("##             SET PORT LOW            ##");
 bannerbase();
 bannerinst();
}
if (level==4)
{
     for(int x=2;x<13;x++)
     {
     Serial.print(digitalRead(x));
     }
     Serial.println(digitalRead(13));
     
   
level=0;
}
}
}

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

spycatcher2k

Just a minor note - the About (function 5) has been removed. But is still on the main menu :-[. Cheers to my youngest son for spotting that, I will sort this on the next update.

Cheers again Arduinees

Spycather2k
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Go Up