connecting two arduinos


hi

my name daniel.
i'm new here.

need code.

i have 2 arduinos, uno , mega.

i want connect both of them.
now connected leds testing, ones code run i'll connect instead of leds other components (ir sensor , step motors).
of course i'll make adjustments components...

here code mega , uno:

-------------------mega----------------
int a;
int b;

void setup()
{
  pinmode(30,input);//connected pin4 on uno
  pinmode(31, input);//connected pin5 on uno
  pinmode(32, output);//connected led 1
  pinmode(33, output);//connected led 2
 
}
 
  void loop()
  {
  a=digitalread(30);
  b=digitalread(31);
   
    if(a=high)
    {zzz();}
    if(a=low)
    {vvv();}
    if(b=high)
    {yyy();}
    if(b=low)
    {www();}
  }
 
  void zzz()
  {
    if(a=high)
 {   
    digitalwrite(32, high);
    digitalwrite(33, low);
}
    else {else();}
  }     
 
 
  void vvv()
  {
    if(a=low)
  { 
    digitalwrite(32, low);
  }
    else {else();}
  }     
 
   void yyy()
  {
    if(b=high)   
   {
    digitalwrite(33, high);
    digitalwrite(32,low);
   }
    else {else();}
  }     
 
  void www()
  {
    if(b=low) 
    {
    digitalwrite(33, low);
  }
    else {else();}
  }       
 
   void else()
   {
     if(a=high)
    {zzz();}
    if(a=low)
    {vvv();}
    if(b=high)
    {yyy();}
    if(b=low)
    {www();}
   }



----------------uno---------------------

int a;
int b;

void setup()
{
  pinmode(2,input);//connected microswitch1
  pinmode(3, input);//connected microswitch2
  pinmode(4, output);//connected pin30 on mega
  pinmode(5, output);//connected pin31 on mega
 
}
 
  void loop()
  {
  a=digitalread(2);
  b=digitalread(3);
   if(a=high)
    {zzz();}
    if(a=low)
    {vvv();}
    if(b=high)
    {yyy();}
    if(b=low)
    {www();}
  }
 
  void zzz()
  {
    if(a=high)
 {   
    digitalwrite(4, high);
    digitalwrite(5, low);
}
    else {else();}
  }     
  void vvv()
  {
    if(a=low)   
    {
    digitalwrite(4, low);}
    else {else();}
  }     
   void yyy()
  {
    if(b=high) 
   {
    digitalwrite(5, high);
  }
    else {else();}
  }     
  void www()
  {
    if(b=low)  {
    digitalwrite(5, low);}
    else {else();}
  }       
   void else()
   {
     if(a=high)
    {zzz();}
    if(a=low)
    {vvv();}
    if(b=high)
    {yyy();}
    if(b=low)
    {www();}
   }


_______________________________

can tell me please problem code?

thanks!

so far, see repetition of ifs inside functions of called zzz , vvv , stuff. remember called if statement already, why evaluate same condition again?

second, rid of useless elses. if plan on using them in future, either comment them out or remember add in future.


also i've noticed use reserved word name function: void else()... if remembre lessons big no-no. rid of elses, want them do?

if aim @ creating loop them, notice lay inside "void loop()". in there automatically repeated on , on , on , rolli'n , cooki'n.


percebes esta frase?


Arduino Forum > Using Arduino > Programming Questions > connecting two arduinos


arduino

Comments