From 97f1d61d612299a2af28b31cb24d3020d7d9bba4 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Tue, 19 May 2015 16:11:33 +0200 Subject: [PATCH] [ES] Added 4.1 Signed-off-by: Jim Martens --- es/blatt4/uebung4-1/uebung4-1.ino | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 es/blatt4/uebung4-1/uebung4-1.ino diff --git a/es/blatt4/uebung4-1/uebung4-1.ino b/es/blatt4/uebung4-1/uebung4-1.ino new file mode 100644 index 0000000..75431d6 --- /dev/null +++ b/es/blatt4/uebung4-1/uebung4-1.ino @@ -0,0 +1,44 @@ +// these variables describe the used hardware pins +// adjust them when you use other pins +// hardware pins +int ledPin = 13; +int analogLevel = 0; + +/** + * Setup function for initial setup code + */ +void setup() { + // Configure pins + analogWrite(ledPin, 0); + + // initialize serial port + Serial.begin(9600); + Serial2.begin(9600); +} + +/** + * Loop function for main code + */ +void loop() { + if (Serial2.available() > 0) { + char command = Serial2.read(); + if (command == '1') { + for (int i = 0; i < 255; i++) { + analogLevel += 1; + analogWrite(ledPin, analogLevel); + Serial.print("LED-Level: "); + Serial.println(analogLevel); + delay(19); + } + Serial2.print('1'); + for (int i = 255; i > 0; i--) { + analogLevel -= 1; + analogWrite(ledPin, analogLevel); + Serial.print("LED-Level: "); + Serial.println(analogLevel); + delay(19); + } + Serial2.print('2'); + } + } +}