1
0
mirror of https://github.com/2martens/uni.git synced 2026-05-06 19:36:26 +02:00

[ES-Blatt2] Finished preparation for 2.3

Signed-óff-by: Jim Martens <github@2martens.de>
This commit is contained in:
2015-04-22 21:08:49 +02:00
parent 1c5ac1f6ca
commit 800f2283d3

View File

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