esercizio 1
int a=1;
void setup() { pinMode(13, OUTPUT);
}
void loop() { if(a<=10){ blink1(); a++;
}
} void blink1(){ digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); delay(500); } |
void setup() { pinMode(13, OUTPUT); for (int a=0; a<10; a++){ blink1(); }
}
void loop() {
}
void blink1(){ digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); delay(500); }
|
esercizio 2
int a=10;
void setup() { pinMode(13, OUTPUT); Serial.begin(9600); while(a>=0){ Serial.println(a); blink1(); a–; } }
void loop() {
}
void blink1(){ digitalWrite(13,HIGH); delay(500); digitalWrite(13,LOW); delay(500); } |
char controllo;
void setup() { pinMode(13, OUTPUT); Serial.begin(9600); Serial.println(“a = veloce; b = piano”); }
void loop() { controllo=Serial.read(); switch(controllo){ case ‘a’: for(int j=1; j<=5; j++){ blink1(); Serial.println(j); } break;
case ‘b’: for(int j=1; j<=5; j++){ blink2(); Serial.println(j); } break; } }
void blink1(){ digitalWrite(13,HIGH); delay(200); digitalWrite(13,LOW); delay(200); }
void blink2(){ digitalWrite(13,HIGH); delay(1000); digitalWrite(13,LOW); delay(1000); } |
esercizio 3
long i=0;
long x=0;
void setup() { pinMode(13, OUTPUT); Serial.begin(9600);
Serial.setTimeout(10);
Serial.println(“scegli il tempo”);
while(Serial.available()==0){} i=Serial.parseInt();
Serial.print(“tempo: “); Serial.println(i); Serial.println(“quante volte?”);
while(Serial.available()==0){} x=Serial.parseInt();
Serial.print(x); Serial.println(” volte”); blink1(i, x); }
|
void loop() { }
void blink1(int time, int y) { for(int j=1; j<=y; j++){ digitalWrite(13,HIGH); delay(time); digitalWrite(13,LOW); delay(time); Serial.println(j); }
} |