Forum >Replies by rodrrigo91
userhead rodrrigo91
Replies (5)
  • You Reply: but how I can read a serie of numbers ? like 1023 and commas.
    I have another problem with this if you can help me it will be very nice.


    I have this code from dfRobot, when I press UP and L1 I want to do  something like turning a led, but actually my code works like this.. I press only one time L1 and y=true, if I press UP the led turns on every time I press UP, if I press both led turns on (that's what I want), how can I fix that problem? I tried to enter several loops there without success

    Code: Select all
    /*
     # Editor : Phoebe
     # Date   : 2014.11.6
     # Ver    : 0.1
     # Product: Devastator Tank Mobile Platform
     # SKU    : RBO0112
     # Description:    
     # Connect the D4,D5,D6,D7,GND to UNO digital 4,5,6,7,GND
     
    */
      
    int E1 = 5;     //M1 Speed Control
    int E2 = 6;     //M2 Speed Control
    int M1 = 13;     //M1 Direction Control
    int M2 = 7;     //M1 Direction Control
    char val;
    boolean y=false;
    boolean x=false;
    boolean z=false;
     
    void stop(void)                    //Stop
    {
       
      digitalWrite(M1,LOW);   
      
    }  
    void advance(void)         //Move forward
    {
      x=true;
      if (z==true)
     { 
       if (x==true && y==true)
       {
         digitalWrite(M1,HIGH); 
         delay(450);
          
          
      }
      else
      {
        x=false;
        y=false;
        z=false;
    }
    
    
    }
    }
    void back_off  (void)         //Move backward
    {
          y=true;
      
      if (y && x)
      {
        z=true;
      }
      else if (y && !x)
      {
        z=false;
        y=false;
      }
        else if (x && !y)
      {
        z=false;
        x=false;
      }
    
    
    
    
     
    }
    void turn_L (char a,char b)             //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)             //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
     
    void setup(void)
    {
      int i;
      for(i=4;i<=13;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
    
      digitalWrite(E1,LOW);  
      digitalWrite(E2,LOW);
     
    }
    
    void serial (void)
    {
          switch(val)
          {
          case 'UP'://Move Forward
            advance ();  //move forward in max speed
            break;
          case 'L1'://Move Backward
            back_off () ;  //move back in max speed
            break;
          case 'BACK'://Turn Left
            turn_L (100,100);    
            break;      
          case 'US'://Turn Right
            turn_R (100,100);
            break;
          case 'v':
            break;
          default:
            stop();
          }
    }
    
    void loop()
    {
      if(Serial.available())
      {
        val = Serial.read();
        serial();
      }
    }
      
    
       
     
  • You Reply: but how I can read a serie of numbers ? like 1023 and commas.
    I have another problem with this if you can help me it will be very nice.


    I have this code from dfRobot, when I press UP and L1 I want to do  something like turning a led, but actually my code works like this.. I press only one time L1 and y=true, if I press UP the led turns on every time I press UP, if I press both led turns on (that's what I want), how can I fix that problem? I tried to enter several loops there without success

    Code: Select all
    /*
     # Editor : Phoebe
     # Date   : 2014.11.6
     # Ver    : 0.1
     # Product: Devastator Tank Mobile Platform
     # SKU    : RBO0112
     # Description:    
     # Connect the D4,D5,D6,D7,GND to UNO digital 4,5,6,7,GND
     
    */
      
    int E1 = 5;     //M1 Speed Control
    int E2 = 6;     //M2 Speed Control
    int M1 = 13;     //M1 Direction Control
    int M2 = 7;     //M1 Direction Control
    char val;
    boolean y=false;
    boolean x=false;
    boolean z=false;
     
    void stop(void)                    //Stop
    {
       
      digitalWrite(M1,LOW);   
      
    }  
    void advance(void)         //Move forward
    {
      x=true;
      if (z==true)
     { 
       if (x==true && y==true)
       {
         digitalWrite(M1,HIGH); 
         delay(450);
          
          
      }
      else
      {
        x=false;
        y=false;
        z=false;
    }
    
    
    }
    }
    void back_off  (void)         //Move backward
    {
          y=true;
      
      if (y && x)
      {
        z=true;
      }
      else if (y && !x)
      {
        z=false;
        y=false;
      }
        else if (x && !y)
      {
        z=false;
        x=false;
      }
    
    
    
    
     
    }
    void turn_L (char a,char b)             //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)             //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
     
    void setup(void)
    {
      int i;
      for(i=4;i<=13;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
    
      digitalWrite(E1,LOW);  
      digitalWrite(E2,LOW);
     
    }
    
    void serial (void)
    {
          switch(val)
          {
          case 'UP'://Move Forward
            advance ();  //move forward in max speed
            break;
          case 'L1'://Move Backward
            back_off () ;  //move back in max speed
            break;
          case 'BACK'://Turn Left
            turn_L (100,100);    
            break;      
          case 'US'://Turn Right
            turn_R (100,100);
            break;
          case 'v':
            break;
          default:
            stop();
          }
    }
    
    void loop()
    {
      if(Serial.available())
      {
        val = Serial.read();
        serial();
      }
    }
      
    
       
     
  • You Reply: yes but I have problems reading data in the receiver by serial using xbee
  • You Reply: yes but I have problems reading data in the receiver by serial using xbee
  • You Reply: I'm trying to recognize the values in the receiver but I can´t find the way to read analog values and characters, It throw me away this data.

    UP,DOWN,
    500,500,500,500 for example... I need to read those analog, can someone help me?