Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Sags doch schnell per LED

5. November 2010

Über den Serial-Monitor können 3 verschiedene Zustände eingegeben werden. j = LED leuchtet n = LED leuchtet nicht p = LED fadet ein und aus Filmchen der 3 verschiedenen Zustände

#define LED 11                // choose the pin for the LED

byte message = 0;
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

void setup(){
pinMode(LED, OUTPUT);         // declare LED as output
Serial.begin(9600);           // open serial port @9600baud
}

void loop(){
 if (Serial.available() > 0){  // check for new data in serial port
 message = Serial.read();
 ja();
 nein();
 pause();
}
//}

void ja(){
 if (message == 'j') {       // check if the input is 'j'
 digitalWrite(LED, HIGH);  // switch the LED on
}
}
void nein(){
 if (message == 'n') {       // check if the input is 'n'
 digitalWrite(LED, LOW);  // switch the LED off
}
}

void pause(){
 if (message == 'p'){      // check if the input is 'p'
 for(int x =0;x<=255;x++){
 analogWrite(LED, brightness);

 brightness = brightness +fadeAmount;        //fade in

 if (brightness <= 1 || brightness >= 254) {
 fadeAmount = fadeAmount* -1 ;       //fade out
 }
 delay(30);
}
}
}