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); } } }