mirror of
https://github.com/2martens/uni.git
synced 2026-05-06 11:26:25 +02:00
[ES-Blatt2] Finished preparation for 2.3
Signed-óff-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -12,8 +12,12 @@ int buttonTwoPin = 3;
|
|||||||
int compareValue = 60;
|
int compareValue = 60;
|
||||||
int rc = 10499;
|
int rc = 10499;
|
||||||
|
|
||||||
// this variable is affected by the buttonOne and buttonTwo actions
|
// this variables are affected by the buttonOne and buttonTwo actions
|
||||||
int volatile counter = 0;
|
// 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
|
// these values are used by the TC0_Handler
|
||||||
// do not use them at all
|
// do not use them at all
|
||||||
@ -67,8 +71,11 @@ void loop() {
|
|||||||
* Has to be changed for the specific use case.
|
* Has to be changed for the specific use case.
|
||||||
*/
|
*/
|
||||||
void buttonOneAction() {
|
void buttonOneAction() {
|
||||||
if (counter < 255) {
|
if (motorState < 2) {
|
||||||
counter += 1;
|
motorState += 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
motorState = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +85,17 @@ void buttonOneAction() {
|
|||||||
* Has to be changed for the specific use case.
|
* Has to be changed for the specific use case.
|
||||||
*/
|
*/
|
||||||
void buttonTwoAction() {
|
void buttonTwoAction() {
|
||||||
if (counter > 0) {
|
if (!motorPowerMaxReached && motorPower < 100) {
|
||||||
counter -= 1;
|
motorPower += 1;
|
||||||
|
}
|
||||||
|
if (motorPowerMaxReached && motorPower > 0) {
|
||||||
|
motorPower -= 1;
|
||||||
|
}
|
||||||
|
if (motorPowerMaxReached && motorPower == 0) {
|
||||||
|
motorPowerMaxReached = false;
|
||||||
|
}
|
||||||
|
if (!motorPowerMaxReached && motorPower == 100) {
|
||||||
|
motorPowerMaxReached = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user