Show Posts
Pages: 1 [2]
16  International / Generale / Re: Pin analogici 6 e 7 su ArduinoBT: come funzionano? on: February 06, 2011, 01:22:32 pm
Il codice così è giusto allora?
(con i cicli  smiley-mr-green):

void setup(){
  for(int i = 0; i > 21; i++){
    if((i != 7) && (i != 0) && (i != 1) && (i != 20) &&(i != 21)){
      pinMode(i, OUTPUT);
    }
  }
  Serial.begin(115200);
}
void loop(){
  byte rec = 0;
  if(Serial.available()){
    rec = Serial.read();
  }
  if((rec != 7) && (rec != 0) && (rec != 1) && (rec != 20) &&(rec != 21) && (rec != 25)){
    digitalWrite(rec, HIGH); 
  }
  else if((rec == 20) || (rec == 21)){
    analogWrite(rec, 255); 
  }
  else if(rec == 25){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);
    digitalWrite(14, LOW);
    digitalWrite(15, LOW);
    digitalWrite(16, LOW);
    digitalWrite(17, LOW);
    digitalWrite(18, LOW);
    digitalWrite(19, LOW);
    analogWrite(20, 0);
    analogWrite(21, 0);

  }
}
17  International / Generale / Re: Pin analogici 6 e 7 su ArduinoBT: come funzionano? on: February 06, 2011, 08:53:13 am
Ed è lo stesso se indico le porte dei pin analogici 6 e 7 con A6 ed A7 o con 20 o 21?
così:
analogWrite(20, 0);
analogWrite(21, 0);
o così:
analogWrite(A6, 0);
analogWrite(A7, 0);
18  International / Generale / Re: Pin analogici 6 e 7 su ArduinoBT: come funzionano? on: February 06, 2011, 08:43:25 am
E devo mettere qualcos'altro al posto di pinMode() o non devo mettere niente? smiley-confuse
19  International / Generale / Pin analogici 6 e 7 su ArduinoBT: come funzionano? on: February 06, 2011, 08:10:54 am
Ciao a tutti, sono nuovo del forum:
Volevo sapere come usare i pin analogici 6 e 7 dell'ArduinoBT come output da 5V;
Io ho usato analogWrite(A6, 255), ma il led connesso al pin non si accende, come mai?
Qua di seguito posto il codice del mio programma:

int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led8 = 8;
int led9 = 9;
int led10 = 10;
int led11 = 11;
int led12 = 12;
int led13 = 13;
int led14 = 14;
int led15 = 15;
int led16 = 16;
int led17 = 17;
int led18 = 18;
int led19 = 19;
int led20 = A6;
int led21 = A7;
void setup(){
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
  pinMode(led11, OUTPUT);
  pinMode(led12, OUTPUT);
  pinMode(led13, OUTPUT);
  pinMode(led14, OUTPUT);
  pinMode(led15, OUTPUT);
  pinMode(led16, OUTPUT);
  pinMode(led17, OUTPUT);
  pinMode(led18, OUTPUT);
  pinMode(led19, OUTPUT);
  pinMode(led20, OUTPUT);
  pinMode(led21, OUTPUT);
  Serial.begin(115200);
}
void loop(){
  byte rec = 0;
  if(Serial.available()){
    rec = Serial.read();
  }
  switch(rec){
    case 2:
      digitalWrite(led2, HIGH);
    break;
    case 3:
      digitalWrite(led3, HIGH);
    break;
    case 4:
      digitalWrite(led4, HIGH);
    break;
    case 5:
      digitalWrite(led5, HIGH);
    break;
    case 6:
      digitalWrite(led6, HIGH);
    break;
    case 8:
      digitalWrite(led8, HIGH);
    break;
    case 9:
      digitalWrite(led9, HIGH);
    break;
    case 10:
      digitalWrite(led10, HIGH);
    break;
    case 11:
      digitalWrite(led11, HIGH);
    break;
    case 12:
      digitalWrite(led12, HIGH);
    break;
    case 13:
      digitalWrite(led13, HIGH);
    break;
    case 14:
      digitalWrite(led14, HIGH);
    break;
    case 15:
      digitalWrite(led15, HIGH);
    break;
    case 16:
      digitalWrite(led16, HIGH);
    break;
    case 17:
      digitalWrite(led17, HIGH);
    break;
    case 18:
      digitalWrite(led18, HIGH);
    break;
    case 19:
      digitalWrite(led19, HIGH);
    break;
    case 20:
      analogWrite(led20, 255);   
    break;
    case 21:
      analogWrite(led21, 255);
    break;
    case 25:
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led6, LOW);
      digitalWrite(led8, LOW);
      digitalWrite(led9, LOW);
      digitalWrite(led10, LOW);
      digitalWrite(led11, LOW);
      digitalWrite(led12, LOW);
      digitalWrite(led13, LOW);
      digitalWrite(led14, LOW);
      digitalWrite(led15, LOW);
      digitalWrite(led16, LOW);
      digitalWrite(led17, LOW);
      digitalWrite(led18, LOW);
      digitalWrite(led19, LOW);
      analogWrite(led20, 0);
      analogWrite(led21, 0);
      break;
  }
}
Grazie mille!
Pages: 1 [2]