From 800f2283d3a8f92753d5d9da10fd9d6c61665ed1 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Wed, 22 Apr 2015 21:08:49 +0200 Subject: [PATCH] [ES-Blatt2] Finished preparation for 2.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-óff-by: Jim Martens --- es/blatt2/uebung2-3/uebung2-3.ino | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/es/blatt2/uebung2-3/uebung2-3.ino b/es/blatt2/uebung2-3/uebung2-3.ino index 0d9a676..d88b341 100644 --- a/es/blatt2/uebung2-3/uebung2-3.ino +++ b/es/blatt2/uebung2-3/uebung2-3.ino @@ -12,8 +12,12 @@ int buttonTwoPin = 3; int compareValue = 60; int rc = 10499; -// this variable is affected by the buttonOne and buttonTwo actions -int volatile counter = 0; +// this variables are affected by the buttonOne and buttonTwo actions +// represents the motor state, can be 0 (clockwise rotation), 1 (anti-clockwise rotation) or 2 (motor stopped) +int volatile motorState = 0; +// represents the power of the motor (range from 0 to 100) +int volatile motorPower = 0; +bool volatile motorPowerMaxReached = false; // these values are used by the TC0_Handler // do not use them at all @@ -67,8 +71,11 @@ void loop() { * Has to be changed for the specific use case. */ void buttonOneAction() { - if (counter < 255) { - counter += 1; + if (motorState < 2) { + motorState += 1; + } + else { + motorState = 0; } } @@ -78,8 +85,17 @@ void buttonOneAction() { * Has to be changed for the specific use case. */ void buttonTwoAction() { - if (counter > 0) { - counter -= 1; + if (!motorPowerMaxReached && motorPower < 100) { + motorPower += 1; + } + if (motorPowerMaxReached && motorPower > 0) { + motorPower -= 1; + } + if (motorPowerMaxReached && motorPower == 0) { + motorPowerMaxReached = false; + } + if (!motorPowerMaxReached && motorPower == 100) { + motorPowerMaxReached = true; } }