Show Posts
Pages: 1 [2]
16  Using Arduino / Programming Questions / Re: Serial.available() on: December 22, 2012, 01:13:44 pm
Quote
Imagine you start "loop" with three characters in the buffer.
You see that Serial.available returns three.
Three is greater than two, so you read one character out.
"loop" exits, gets called again, and you call Serial.available again
What happens next?

Code:
void setup(){
  Serial.begin(9600);
}

void loop(){
  if(Serial.available()>2){
  char inBytes=Serial.read();
  Serial.println(inBytes);
  }
  
}

  

first three characters typed:
"567"
Serial returns
"5"
(as you said)
going on with serial input, for example with
"sg89"
i get
"67sg"
ecc...

so, opening for the very first time the serial monitor, while less than 3 char are typed,
no signal is returned. When 3 or more char are entered, serial data began to flow from Arduino to pc.
Buffer does not reset each time the loop() cycle begin, for this reason, just when i open for the first time the serial port, this happens.
Right?...
my goodness, i'm sweating...
17  Using Arduino / Programming Questions / Re: Serial.available() on: December 22, 2012, 10:33:45 am
Quote
It would be really helpful if you would explain what application you are using to send the data, what options you have set, and how, exactly, you are sending the data.

To send data to Arduino, i use the serial monitor launched from the Arduino IDE.
My purpose is to send ASCII codes (so composed by one ore more digits) to Arduino and get back the corresponding character....is it possible...?

Quote
Think about what you have.
Imagine you start "loop" with three characters in the buffer.
Think about what will happen to Serial.available after you have read out one character.

I'm not able to figure it out...no ideas..
 
18  Using Arduino / Programming Questions / Re: How to Activate and Deactivate Switches? on: December 22, 2012, 09:23:01 am
as i said, i'm totally new...
im sorry!
Code:
int Bu1=9;
int Bu2=10;
int Bu3=11;

int L1=3;
int L2=4;
int L3=5;

int buzz=2;

void setup(){
  for(int x=3;x<6;x++){
    pinMode(x,OUTPUT);
  }
  for (int x=9;x<12;x++){
    pinMode(x,INPUT);
  }
}

void loop(){
 
  int ledarray[]={3,4,5};
  int buttonstate[]={digitalRead(Bu1),digitalRead(Bu2),digitalRead(Bu3)};
 
  for(int x=0;x<3;x++){
    if (buttonstate[x]==1){
      digitalWrite(ledarray[x],HIGH);
      tone(buzz,440,2000);
      delay(30000);
      digitalWrite(ledarray[x],LOW);
      delay(10);
    }
   
  }
 
}
     
19  Using Arduino / Programming Questions / Re: How to Activate and Deactivate Switches? on: December 22, 2012, 08:59:31 am
//Hi!
//i'm new too with Arduino:
//try that sketch; i built the circuit and all worked well.

//notide that
int Bu1=9;
int Bu2=10;
int Bu3=11;

int L1=3;
int L2=4;
int L3=5;

int buzz=2;

void setup(){
//i could initialize the pins one by one,
//but this method is quite handy, and i made it mine
  for(int x=3;x<6;x++){
    pinMode(x,OUTPUT);
  }
  for (int x=9;x<12;x++){
    pinMode(x,INPUT);
  }
}

void loop(){
 
  int ledarray[]={3,4,5};
  int buttonstate[]={digitalRead(Bu1),digitalRead(Bu2),digitalRead(Bu3)};
 
  for(int x=0;x<3;x++){
    if (buttonstate
  • ==1){
      digitalWrite(ledarray
  • ,HIGH);
      tone(buzz,440,2000);
//while waiting nothing can happen
//so other buttons cannot be read
      delay(30000);
      digitalWrite(ledarray
  • ,LOW);
      delay(10);
    }
   
  }
 
}

//hope you'll enjoy!
// if you need, i may post the circuit scheme made with fritzing!
20  Using Arduino / Programming Questions / Re: Serial.available() on: December 22, 2012, 07:55:22 am
Thanks a lot!
but, sorry, for me it's still a bit misleading...
//in this case:
void loop(){
  if (Serial.available()>2){
    int inByte=Serial.read();
    Serial.println(inByte);
  }
}

/* after uploading the sketch, typing a number of char, in the serial window, lower than 3,
no replies are obtained.
actually, after 4 or more characters are entered, even if just new one is typed, Arduino  sends the corresponding
ASCII code back.
How can I change the sketch, so only if 2 or more characters are entered, replies are sent, at any moment?
I hope i've been clear...*/

21  Using Arduino / Programming Questions / Re: Serial.available() on: December 22, 2012, 05:43:14 am
So, typing:
if (Serial.available()==3){
...
}
Arduino gets data from computer, if you insert three characters only?
is that correct?
 
22  Using Arduino / Programming Questions / Serial.available() on: December 21, 2012, 01:25:46 pm
Not clear the meaning of Serial.available() function.
Can someone help!?

thanks
Pages: 1 [2]