Wenn-Programm
Aus RMG-Wiki
void setup() { pinMode(13,OUTPUT); pinMode(7,INPUT); } void loop() { if(digitalRead(7)==HIGH) { digitalWrite(13,HIGH); } if(digitalRead(7)==LOW) { digitalWrite(13,LOW); } }
anderes:
void setup()
{
pinMode(7,OUTPUT); //LED pinMode(8,OUTPUT); //Lautsprecher
} void loop() {
digitalWrite(7,HIGH); //LED an delay(2000); // 2sec verz. digitalWrite(7,LOW); //Led aus tone(8,20000,1000); // Ton an delay(2000); // 2sec verz.
}
Mit Schalter:
void setup() {
pinMode(9,INPUT); pinMode(2,OUTPUT);
} void loop() {
if(digitalRead(9)==HIGH) { digitalWrite(2,HIGH); } else { digitalWrite(2,LOW); }
}