Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Arduin and C# on: June 17, 2010, 02:23:03 pm
Hi, I'm using C# to send values to my arduino such as 12 and 24 to my arduino. I've got the coding were my arduino reads 12 if i send <12> from C# and when i send * an infinte for loop is activated. Now I got the infinite for loop to go from 0 to 15 and start again from 0 to 15 and this will keep on going until the arduino is switched on.

my infite for loop  
for (int b = 0; b<17; b++)
{
 look what is the value of serialValue
and do something
}

I did this infinite for loop because i'm storing the C# values on the ardunio, which are then stored in an array called serialValues, and when i send * from C# the infinte loop starts.
As explaind i want the arduino to go through all the values it received and if it receives 12 and pin 10 is high then pin 12 is high etc..

the problem i'm facing is that when the infite loop starts again from 0 and the value 12 reappeard from the array and pin 10 is low, pin 12 remains high and i want it to go LOW. And when b starts from 0 again and pin 10 is high i want pin12 u go high again

HERE is my coding I would appreciate any help cause i'm a college student and i need to solve this problme ASAP

#

for infinite i was referring for b is 0, it increment by 1 and when the value is equal to 16, it will set b 0 and start all over again and will continue doing that untill the arduino is powered.

Thanks
Matthew
2  Forum 2005-2010 (read only) / Troubleshooting / Arduin and C# on: June 17, 2010, 02:13:50 pm
Hi, I'm using C# to send values to my arduino such as 12 and 24 to my arduino. I've got the coding were my arduino reads 12 if i send <12> from C# and when i send * an infinte for loop is activated. Now I got the infinite for loop to go from 0 to 15 and start again from 0 to 15 and this will keep on going until the arduino is switched on.

my infite for loop  
for (int b = 0; b<17; b++)
 {
  look what is the value of serialValue
 and do something
}

I did this infinite for loop because i'm storing the C# values on the ardunio, which are then stored in an array called serialValues, and when i send * from C# the infinte loop starts.
As explaind i want the arduino to go through all the values it received and if it receives 12 and pin 10 is high then pin 12 is high etc..

the problem i'm facing is that when the infite loop starts again from 0 and the value 12 reappeard from the array and pin 10 is low, pin 12 remains high and i want it to go LOW. And when b starts from 0 again and pin 10 is high i want pin12 u go high again

HERE is my coding I would appreciate any help cause i'm a college student and i need to solve this problme ASAP

char inData[10];
int index;
boolean started = false;
boolean ended = false;
boolean final = false;
int serialValues[16];
int serialIndex = 0;
const int Pin13 =  13;
const int Pin12 =  12;
const int Pin11 =  11;
const int Pin10 =  10;
int buttonState1 = 0;
int buttonState2 = 0;


  void setup()
    {
    //Serial1.begin(9600);
    Serial.begin(9600);

    //setting pinouts
    pinMode(Pin13, OUTPUT);
    pinMode(Pin12, OUTPUT);
    pinMode(Pin11, INPUT);
    pinMode(Pin10, INPUT);
    }

  void loop()
    {
      buttonState1 = digitalRead(Pin11);
      buttonState2 = digitalRead(Pin10);
      
      while(Serial.available() > 0)
        {
         char aChar = Serial.read();
         if(aChar == '<')
           {
             started = true;
             index = 0;
             inData[index] = '\0';
           }
         else if(aChar == '>')
           {
             ended = true;
           }
      
           else if(started)
           {
             inData[index] = aChar;
             index++;
             inData[index] = '\0';            
             }
        
           else if (aChar =='*')
             {
               final = true;
             }
        }
  

      if(started && ended)
        {
         // Convert the string to an integer
         int inInt = atoi(inData);
           Serial.println(inInt);
         // Use the value
           serialValues [serialIndex] = inInt;
         serialIndex++;
        
           // Get ready for the next time
         started = false;
         ended = false;

         index = 0;
         inData[index] = '\0';      
        }
  
      if(final)
            while(1)
{
            // loop through the serialValues, and do something
            for(int b=0; b <16;b++ )
             {
              
                int nextVal = serialValues;
                //if serial value is 24 and pin10 is connected to 5V switch led12 on
                if (nextVal == 24 && buttonState2 == HIGH)
                   {
                   digitalWrite(Pin12, HIGH);                                                        
                   }
                 //if serial value is 12 and pin11 is connected to 5V switch led13 on
                 if (nextVal == 12 && buttonState2 == LOW)
                   {
                   digitalWrite(Pin12, LOW);                                                        
                 }
                  Serial.println(b);
                   delay(1000);              
              
         }
   }
    }
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: string to int (pwm) on: June 01, 2010, 01:14:18 pm
Hi, I've got a similar problem. I'm using C# and I'm sending 16 integer values such as 12,458,789,13,45,89,100,57,36,46,96,123,658,758,45,67 via a serial communication. Now when i send those values from C# to the arduino, i want my aruino to store them inti an array such as
 
    Value[0] = 12;
    Value[1] = 458;
    Value[2] = 789;
    etc...

I'm able to send 12 from C# and then the arduino reads each character and store array[0] = 1 & array[1] = 2 but i want to be able to store the whole integer. Any Help?

Regards,
Matthew

4  Forum 2005-2010 (read only) / Interfacing / serial send 0 -1023 value on: January 12, 2011, 03:02:38 pm
Hi, I have a 10bit rotary encoder, which translates 360 degrees into a range of 0 -1023, and I want to send the value to Matlab. I'm trying to send 2 Bytes,  using 8 bits in 1 Byte and 2 bits of an other byte. I'm send for example a value of 1024 and get 3252 send. The 10 bit value is send from the arduino to maltab when an integer greater than 19 is sent to the arduino.

This is my code so far.

int incomingvalue = 0;
unsigned int  val;           // This is a 16 bit value
byte msb;           // 8 bit variable to hold the most significant byte
byte lsb;           // 8 bit variable to hold the least significant byte

  void setup()
    {
     Serial.begin(9600);    
     pinMode(13, OUTPUT);
    }
      
  void loop()
     {            
      if (Serial.available())
        {
          incomingvalue = (int)Serial.read();  
          if (incomingvalue > 19)
          {        
           //this is the value that is to be send to matlab
           val = 1020;
           digitalWrite(13, HIGH);   // set the LED on, communication ok
           Serial.write(lowByte(val));
           Serial.write(highByte(val));
          }
        
          if (incomingvalue < 19)
          {        
          Serial.print(1);
          }
      }
 
  }

Hope someone can help, thanks.
5  Forum 2005-2010 (read only) / Interfacing / Re: Serial communication problem on: January 11, 2011, 01:35:06 pm
Hi all,
I'm interfacing a simulink model with arduino and sending 8bit values (0 to 255) values to and from the arduino. The problem is that I now need to send 10bit values (0 to 1023) to and from the arduino but so far I did not manage to do that.

Any idea?

Thanks.
6  Forum 2005-2010 (read only) / Interfacing / Re: integer bigger than 32 on: June 21, 2010, 05:11:14 pm
thanks lefty smiley
7  Forum 2005-2010 (read only) / Interfacing / Re: integer bigger than 32 on: June 21, 2010, 04:36:14 pm
hi lefty, thanks for the info. this is my code, how shall i use the unisigned integer so that it will accept a value bigger than 32767

char inData[10];
int index;
boolean started = false;
boolean ended = false;
boolean final = false;
int serialValues[16];
int serialIndex = 0;
const int Pin13 =  13;
const int Pin12 =  12;
const int Pin11 =  11;
const int Pin10 =  10;
const int Pin7 = 7;
const int Pin6 = 6;
const int Pin5 = 5;
const int Pin4 = 4;




int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;


//int lastButtonState = 0;

  void setup()
    {
    //Serial1.begin(9600);
    Serial.begin(9600);

    //setting pinouts
    pinMode(Pin13, INPUT);
    pinMode(Pin12, INPUT);
    pinMode(Pin11, INPUT);
    pinMode(Pin10, INPUT);
    
    pinMode(Pin7, OUTPUT);
    pinMode(Pin6, OUTPUT);
    pinMode(Pin5, OUTPUT);
    pinMode(Pin4, OUTPUT);
    
    }

  void loop()      
    {  
      while(Serial.available() > 0)
        {
         char aChar = Serial.read();
         if(aChar == '<')
           {
             started = true;
             index = 0;
             inData[index] = '\0';
           }
         else if(aChar == '>')
           {
             ended = true;
           }
      
           else if(started)
           {
             inData[index] = aChar;
             index++;
             inData[index] = '\0';            
             }
        
           else if (aChar =='*')
             {
               final = true;
             }
        }
  

      if(started && ended)
        {
         // Convert the string to an integer
         int inInt = atoi(inData);
           Serial.println(inInt);
         // Use the value
           serialValues [serialIndex] = inInt;
         serialIndex++;
        
           // Get ready for the next time
         started = false;
         ended = false;

         index = 0;
         inData[index] = '\0';      
        }
  
      if(final)
            while(1)
           {
            // loop through the serialValues, and do something
            for(int b=0; b <3;b++ )
             {
              buttonState1 = digitalRead(Pin13);
                buttonState2 = digitalRead(Pin12);
                buttonState3 = digitalRead(Pin11);
                buttonState4 = digitalRead(Pin10);
                
                int nextVal = serialValues;
              
                // I1 and any output
                
                   if (nextVal == 384 && buttonState1 == HIGH)                  
                   digitalWrite(Pin7, HIGH);      //Q1                              
                   else if (nextVal == 384 && buttonState1 == LOW)                  
                   digitalWrite(Pin7, LOW);      //Q1
                  
                   if (nextVal == 1152 && buttonState1 == HIGH)                
                   digitalWrite(Pin6, HIGH);      //Q2                              
                   else if (nextVal == 1152 && buttonState1 == LOW)                
                   digitalWrite(Pin6, LOW);      //Q2
                  
                   if (nextVal == 2176 && buttonState1 == HIGH)
                   digitalWrite(Pin5, HIGH);     //Q3  
                   else if (nextVal == 2176 && buttonState1 == LOW)
                   digitalWrite(Pin5, LOW);     //Q3                  
    
                   if (nextVal == 4224 && buttonState1 == HIGH)
                   digitalWrite(Pin4, HIGH);     //Q4                              
                   else if (nextVal == 4224 && buttonState1 == LOW)
                   digitalWrite(Pin4, LOW);     //Q4
                  
                   if (nextVal == 8320 && buttonState1 == HIGH)
                   digitalWrite(Pin7, LOW);     //Q1^
                   else if (nextVal == 8320 && buttonState1 == LOW)
                   digitalWrite(Pin7, HIGH);    //Q1^            
                  
                   if (nextVal == 16512 && buttonState1 == HIGH)
                   digitalWrite(Pin6, LOW);     //Q2^
                   else if (nextVal == 16512 && buttonState1 == LOW)
                   digitalWrite(Pin6, HIGH);    //Q2^              
                  
                   if (nextVal == 32896 && buttonState1 == HIGH)
                   digitalWrite(Pin5, LOW);     //Q3^
                   else if (nextVal == 32896 && buttonState1 == LOW)
                   digitalWrite(Pin5, HIGH);    //Q3^              
                  
                   if (nextVal == 65664 && buttonState1 == HIGH)
                   digitalWrite(Pin5, LOW);     //Q4^
                   if (nextVal == 65664 && buttonState1 == LOW)
                   digitalWrite(Pin5, HIGH);    //Q4^              
                  
                   // I2 and any output
                
                   if (nextVal == 320 && buttonState2 == HIGH)                  
                   digitalWrite(Pin7, HIGH);      //Q1                              
                   else if (nextVal == 320 && buttonState2 == LOW)                  
                   digitalWrite(Pin7, LOW);      //Q1
                  
                   if (nextVal == 1088 && buttonState2 == HIGH)                
                   digitalWrite(Pin6, HIGH);      //Q2                              
                   else if (nextVal == 1088 && buttonState2 == LOW)                
                   digitalWrite(Pin6, LOW);      //Q2
                  
                   if (nextVal == 2112 && buttonState2 == HIGH)
                   digitalWrite(Pin5, HIGH);     //Q3  
                   else if (nextVal == 2112 && buttonState2 == LOW)
                   digitalWrite(Pin5, LOW);     //Q3                  
    
                   if (nextVal == 4160 && buttonState2 == HIGH)
                   digitalWrite(Pin4, HIGH);     //Q4                              
                   else if (nextVal == 4160 && buttonState2 == LOW)
                   digitalWrite(Pin4, LOW);     //Q4
                  
                   if (nextVal == 8256 && buttonState2 == HIGH)
                   digitalWrite(Pin7, LOW);     //Q1^
                   else if (nextVal == 8256 && buttonState2 == LOW)
                   digitalWrite(Pin7, HIGH);    //Q1^            
                  
                   if (nextVal == 16448 && buttonState2 == HIGH)
                   digitalWrite(Pin6, LOW);     //Q2^
                   else if (nextVal == 16448 && buttonState2 == LOW)
                   digitalWrite(Pin6, HIGH);    //Q2^              
                  
                   if (nextVal == 32832 && buttonState2 == HIGH)
                   digitalWrite(Pin5, LOW);     //Q3^
                   else if (nextVal == 32832 && buttonState2 == LOW)
                   digitalWrite(Pin5, HIGH);    //Q3^              
                  
                   if (nextVal == 65600 && buttonState2 == HIGH)
                   digitalWrite(Pin5, LOW);     //Q4^
                   if (nextVal == 65600 && buttonState2 == LOW)
                   digitalWrite(Pin5, HIGH);    //Q4^
                  
                   // I3 and any output
                  
                   if (nextVal == 288 && buttonState3 == HIGH)                  
                   digitalWrite(Pin7, HIGH);      //Q1                              
                   else if (nextVal == 288 && buttonState3 == LOW)                  
                   digitalWrite(Pin7, LOW);      //Q1
                  
                   if (nextVal == 1056 && buttonState3 == HIGH)                
                   digitalWrite(Pin6, HIGH);      //Q2                              
                   else if (nextVal == 1056 && buttonState3 == LOW)                
                   digitalWrite(Pin6, LOW);      //Q2
                  
                   if (nextVal == 2080 && buttonState3 == HIGH)
                   digitalWrite(Pin5, HIGH);     //Q3  
                   else if (nextVal == 2080 && buttonState3 == LOW)
                   digitalWrite(Pin5, LOW);     //Q3                  
    
                   if (nextVal == 4128 && buttonState3 == HIGH)
                   digitalWrite(Pin4, HIGH);     //Q4                              
                   else if (nextVal == 4128 && buttonState3 == LOW)
                   digitalWrite(Pin4, LOW);     //Q4
                  
                   if (nextVal == 8224 && buttonState3 == HIGH)
                   digitalWrite(Pin7, LOW);     //Q1^
                   else if (nextVal == 8224 && buttonState3 == LOW)
                   digitalWrite(Pin7, HIGH);    //Q1^            
                  
                   if (nextVal == 16416 && buttonState3 == HIGH)
                   digitalWrite(Pin6, LOW);     //Q2^
                   else if (nextVal == 16416 && buttonState3 == LOW)
                   digitalWrite(Pin6, HIGH);    //Q2^              
                  
                   if (nextVal == 32800 && buttonState3 == HIGH)
                   digitalWrite(Pin5, LOW);     //Q3^
                   else if (nextVal == 32800 && buttonState3 == LOW)
                   digitalWrite(Pin5, HIGH);    //Q3^              
                  
                   if (nextVal == 65568 && buttonState3 == HIGH)
                   digitalWrite(Pin5, LOW);     //Q4^
                  
                  
8  Forum 2005-2010 (read only) / Interfacing / integer bigger than 32 on: June 21, 2010, 04:11:47 pm
Hi, I'm sending intger numbers from C# to my arduino. Each number is send as character character and in order for the arduino to know the exacy integer value i'm sendin my value in brakets such as <123> this way the arduino will tell that the integer value is 123. Know my problem is that i want to send an integer 65600 but

int will only hold a number which is smaller than 32768

i tried to change the variable int = inInt  to long = inInt but i can not make it work. below is my code

#      
9  Forum 2005-2010 (read only) / Interfacing / ARduino + C# on: June 17, 2010, 02:13:15 pm
Hi, I'm using C# to send values to my arduino such as 12 and 24 to my arduino. I've got the coding were my arduino reads 12 if i send <12> from C# and when i send * an infinte for loop is activated. Now I got the infinite for loop to go from 0 to 15 and start again from 0 to 15 and this will keep on going until the arduino is switched on.

my infite for loop  
for (int b = 0; b<17; b++)
 {
  look what is the value of serialValue
 and do something
}

I did this infinite for loop because i'm storing the C# values on the ardunio, which are then stored in an array called serialValues, and when i send * from C# the infinte loop starts.
As explaind i want the arduino to go through all the values it received and if it receives 12 and pin 10 is high then pin 12 is high etc..

the problem i'm facing is that when the infite loop starts again from 0 and the value 12 reappeard from the array and pin 10 is low, pin 12 remains high and i want it to go LOW. And when b starts from 0 again and pin 10 is high i want pin12 u go high again

HERE is my coding I would appreciate any help cause i'm a college student and i need to solve this problme ASAP

char inData[10];
int index;
boolean started = false;
boolean ended = false;
boolean final = false;
int serialValues[16];
int serialIndex = 0;
const int Pin13 =  13;
const int Pin12 =  12;
const int Pin11 =  11;
const int Pin10 =  10;
int buttonState1 = 0;
int buttonState2 = 0;


  void setup()
    {
    //Serial1.begin(9600);
    Serial.begin(9600);

    //setting pinouts
    pinMode(Pin13, OUTPUT);
    pinMode(Pin12, OUTPUT);
    pinMode(Pin11, INPUT);
    pinMode(Pin10, INPUT);
    }

  void loop()
    {
      buttonState1 = digitalRead(Pin11);
      buttonState2 = digitalRead(Pin10);
      
      while(Serial.available() > 0)
        {
         char aChar = Serial.read();
         if(aChar == '<')
           {
             started = true;
             index = 0;
             inData[index] = '\0';
           }
         else if(aChar == '>')
           {
             ended = true;
           }
      
           else if(started)
           {
             inData[index] = aChar;
             index++;
             inData[index] = '\0';            
             }
        
           else if (aChar =='*')
             {
               final = true;
             }
        }
  

      if(started && ended)
        {
         // Convert the string to an integer
         int inInt = atoi(inData);
           Serial.println(inInt);
         // Use the value
           serialValues [serialIndex] = inInt;
         serialIndex++;
        
           // Get ready for the next time
         started = false;
         ended = false;

         index = 0;
         inData[index] = '\0';      
        }
  
      if(final)
            while(1)
{
            // loop through the serialValues, and do something
            for(int b=0; b <16;b++ )
             {
              
                int nextVal = serialValues;
                //if serial value is 24 and pin10 is connected to 5V switch led12 on
                if (nextVal == 24 && buttonState2 == HIGH)
                   {
                   digitalWrite(Pin12, HIGH);                                                        
                   }
                 //if serial value is 12 and pin11 is connected to 5V switch led13 on
                 if (nextVal == 12 && buttonState2 == LOW)
                   {
                   digitalWrite(Pin12, LOW);                                                        
                 }
                  Serial.println(b);
                   delay(1000);              
              
         }
   }
    }
10  Forum 2005-2010 (read only) / Interfacing / Re: Interface arduino with C# - PLC on: March 31, 2010, 06:47:57 am
Yes as "pin 3" I'm refering to the value read from pin 3.

Yes my mistake, i'm refering to digital pins and i should have writen  ==1 not > 1. I'm refering to 1 as when i'll apply 5V on the digital input pin
11  Forum 2005-2010 (read only) / Interfacing / Re: Interface arduino with C# - PLC on: March 31, 2010, 05:43:25 am
Well first of all thanks for the feedback. The 12 is a value that is assigned to the by the C# form and when i send the data the arduino will receive an array in which the value 12 will appear.

Now on the arduino i'll do the following

set pin 3 as input
set pin 4 as input
set pin 5 as input
set pin 6 as input

set pin 7 as output
set pin 8 as output
set pin 9 as output
set pin 10 as output

case array == 12
      {
       if pin 3 > 1 and pin 4>1
           {
            pin 7 == 1
            }
       }

case array == 22
      {
       if pin 4 > 1 or pin 6>1
           {
            pin 8 == 1
            }
       }
12  Forum 2005-2010 (read only) / Interfacing / Interface arduino with C# - PLC on: March 31, 2010, 03:18:10 am
Hi, I'm a college student and I'm building a PLC. What I'm trying to do is to create a C# form that allows me to design my  ladder program and  then send it to the arduino. My plan is to give a certain value to each line as
         I1        I2       Q1
     ---| |------| |-----(   )---         =   12
This means that if I 'AND' two inputs with the result will be shown on output Q1. For each line the C# will generate a number (in this case 12) and store it in an array and send the array to the arduin so that when the arduino reads 12 it will set AND 2 inputs together (pins 2 + 3) and show the result on pin 8.

I need some help on how can i make the arduino read an array that has 16 intiger values to it and for every integer a "case switch" has to be applicable. This array has to be stored on the arduino and can only be deleted or written over using tha C# form.

Thanks Warne
13  Forum 2005-2010 (read only) / News / Interface arduino with C# on: June 17, 2010, 01:21:01 pm
Hi, I'm using C# to send values to my arduino such as 12 and 24 to my arduino. I've got the coding were my arduino reads 12 if i send <12> from C# and when i send * an infinte for loop is activated. Now I got the infinite for loop to go from 0 to 15 and start again from 0 to 15 and this will keep on going until the arduino is switched on.

my infite for loop  
for (int b = 0; b<17; b++)
  {
   look what is the value of serialValue
  and do something
}

I did this infinite for loop because i'm storing the C# values on the ardunio, which are then stored in an array called serialValues, and when i send * from C# the infinte loop starts.
As explaind i want the arduino to go through all the values it received and if it receives 12 and pin 10 is high then pin 12 is high etc..

the problem i'm facing is that when the infite loop starts again from 0 and the value 12 reappeard from the array and pin 10 is low, pin 12 remains high and i want it to go LOW. And when b starts from 0 again and pin 10 is high i want pin12 u go high again

HERE is my coding I would appreciate any help cause i'm a college student and i need to solve this problme ASAP

#
14  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Byte array on: June 21, 2010, 12:07:32 pm
hey paul thanks but i managed to do it. what i was intend to do was to start a loop when a command is inputted to the arduino. This loop goes from 0 to 12 and when b== 12, then b is set to 0 (b=0) so that the loop will start over again, and continue until the arduino is switched off. that is why i called it and infinite loop smiley

thanks again
Regards
Warne
15  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Byte array on: June 17, 2010, 02:00:30 pm
Hi, I'm using C# to send values to my arduino such as 12 and 24 to my arduino. I've got the coding were my arduino reads 12 if i send <12> from C# and when i send * an infinte for loop is activated. Now I got the infinite for loop to go from 0 to 15 and start again from 0 to 15 and this will keep on going until the arduino is switched on.

my infite for loop  
for (int b = 0; b<17; b++)
 {
  look what is the value of serialValue
 and do something
}

I did this infinite for loop because i'm storing the C# values on the ardunio, which are then stored in an array called serialValues, and when i send * from C# the infinte loop starts.
As explaind i want the arduino to go through all the values it received and if it receives 12 and pin 10 is high then pin 12 is high etc..

the problem i'm facing is that when the infite loop starts again from 0 and the value 12 reappeard from the array and pin 10 is low, pin 12 remains high and i want it to go LOW. And when b starts from 0 again and pin 10 is high i want pin12 u go high again

HERE is my coding I would appreciate any help cause i'm a college student and i need to solve this problme ASAP

char inData[10];
int index;
boolean started = false;
boolean ended = false;
boolean final = false;
int serialValues[16];
int serialIndex = 0;
const int Pin13 =  13;
const int Pin12 =  12;
const int Pin11 =  11;
const int Pin10 =  10;
int buttonState1 = 0;
int buttonState2 = 0;


  void setup()
    {
    //Serial1.begin(9600);
    Serial.begin(9600);

    //setting pinouts
    pinMode(Pin13, OUTPUT);
    pinMode(Pin12, OUTPUT);
    pinMode(Pin11, INPUT);
    pinMode(Pin10, INPUT);
    }

  void loop()
    {
      buttonState1 = digitalRead(Pin11);
      buttonState2 = digitalRead(Pin10);
      
      while(Serial.available() > 0)
        {
         char aChar = Serial.read();
         if(aChar == '<')
           {
             started = true;
             index = 0;
             inData[index] = '\0';
           }
         else if(aChar == '>')
           {
             ended = true;
           }
      
           else if(started)
           {
             inData[index] = aChar;
             index++;
             inData[index] = '\0';            
             }
        
           else if (aChar =='*')
             {
               final = true;
             }
        }
  

      if(started && ended)
        {
         // Convert the string to an integer
         int inInt = atoi(inData);
           Serial.println(inInt);
         // Use the value
           serialValues [serialIndex] = inInt;
         serialIndex++;
        
           // Get ready for the next time
         started = false;
         ended = false;

         index = 0;
         inData[index] = '\0';      
        }
  
      if(final)
            while(1)
{
            // loop through the serialValues, and do something
            for(int b=0; b <16;b++ )
             {
              
                int nextVal = serialValues;
                //if serial value is 24 and pin10 is connected to 5V switch led12 on
                if (nextVal == 24 && buttonState2 == HIGH)
                   {
                   digitalWrite(Pin12, HIGH);                                                        
                   }
                 //if serial value is 12 and pin11 is connected to 5V switch led13 on
                 if (nextVal == 12 && buttonState2 == LOW)
                   {
                   digitalWrite(Pin12, LOW);                                                        
                 }
                  Serial.println(b);
                   delay(1000);              
              
         }
   }
    }
Pages: [1] 2