Pages: [1]   Go Down
Author Topic: comunicazione seriale (prima prova in assoluto)  (Read 898 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 313
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

È il primo programma che modifico rispetto agli esempi.
Volevo cambiare il pin di “blink” tramite comando da pc.
Spedisco il numero corrispondente al pin che voglio blincare.
Perché nn funziona? (arduino mega e uso il serial monitor fornito)
Code:
int ledPin =  22;    // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);  
  Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
}  


// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  // send data only when you receive data:
  if (Serial.available() > 0) {
  // read the incoming byte:
  int ledPin1 = Serial.read();
  digitalWrite(ledPin, LOW); // set the LED off
  ledPin=ledPin1; // changethe LED
}
  //say what you got:
  Serial.print("I received: ");
  Serial.println(ledPin, DEC);
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second

}
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 313
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

GRAZIE  ... mi ero dimenticato ...
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 313
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

in realtà funzica, ma ...  mi legge un byte alla volta e con numeri sotto al 31 ho comunque dei problemi ... mi date una mano  a codificare i valori che insrisco?
potrei benissimo fare una differenza .. ma...
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 313
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok .. questo con una tabella asci si riescono a comandare le porte tramite hyperterminal o un qualsiasi programma di comunicazione com anche con arduino mega :

Code:
int ledPin =  22;    // LED connected to digital pin 22

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);  
  Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
}  


// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  // send data only when you receive data:
  if (Serial.available() > 0) {
  // read the incoming byte:
  int ledPin1 = Serial.read();
  digitalWrite(ledPin, LOW);    // set the LED off
  ledPin= ledPin1-32; //change the Led
   pinMode(ledPin, OUTPUT);  
 }
  //say what you got:
  Serial.print("I received: ");
  Serial.println(ledPin, DEC);
  digitalWrite(ledPin, HIGH);  // set the LED on
  //delay(1000);                  // wait for a second
  //digitalWrite(ledPin, LOW);    // set the LED off
  //delay(1000);                  // wait for a second

}

ho un paio di cose da capire se .. si può incrementare il buffer di ricezione a + caratteri
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 313
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

è normale che se fermo il programma di comunicazione .. anhe il programma si blocca ?
Logged

Pages: [1]   Go Up
Jump to: