mirror of
https://github.com/2martens/uni.git
synced 2026-05-06 11:26:25 +02:00
[ES-Blatt2] Generalized button names
Signed-óff-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -2,10 +2,10 @@
|
|||||||
// adjust them when you use other pins
|
// adjust them when you use other pins
|
||||||
// hardware pin for the LED
|
// hardware pin for the LED
|
||||||
int ledPin = 7;
|
int ledPin = 7;
|
||||||
// hardware pin for the plus button
|
// hardware pin for button 1
|
||||||
int buttonPlusPin = 5;
|
int buttonOnePin = 5;
|
||||||
// hardware pin for the minus button
|
// hardware pin for button 2
|
||||||
int buttonMinusPin = 3;
|
int buttonTwoPin = 3;
|
||||||
|
|
||||||
// used to achieve a 1kHz frequency
|
// used to achieve a 1kHz frequency
|
||||||
// don't touch them
|
// don't touch them
|
||||||
@ -14,10 +14,12 @@ int rc = 10499;
|
|||||||
|
|
||||||
// these values are used by the TC0_Handler
|
// these values are used by the TC0_Handler
|
||||||
// do not write into them within the loop/setup
|
// do not write into them within the loop/setup
|
||||||
// only the counter should be used within the loop
|
// only the counter, buttonOnePressed and buttonTwoPressed should be used within the loop
|
||||||
int volatile counter = 0;
|
int volatile counter = 0;
|
||||||
int timesPressedPlus = 0;
|
bool volatile buttonOnePressed = false;
|
||||||
int timesPressedMinus = 0;
|
bool volatile buttonTwoPressed = false;
|
||||||
|
int timesPressedOne = 0;
|
||||||
|
int timesPressedTwo = 0;
|
||||||
bool increased = false;
|
bool increased = false;
|
||||||
bool decreased = false;
|
bool decreased = false;
|
||||||
|
|
||||||
@ -42,8 +44,8 @@ void setup() {
|
|||||||
TC_Start(TC0, 0);
|
TC_Start(TC0, 0);
|
||||||
|
|
||||||
// Configure button pins for input mode
|
// Configure button pins for input mode
|
||||||
pinMode(buttonPlusPin, INPUT);
|
pinMode(buttonOnePin, INPUT);
|
||||||
pinMode(buttonMinusPin, INPUT);
|
pinMode(buttonTwoPin, INPUT);
|
||||||
|
|
||||||
// initialize serial port
|
// initialize serial port
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@ -90,46 +92,46 @@ void TC0_Handler()
|
|||||||
// request static for some magic behind the curtain
|
// request static for some magic behind the curtain
|
||||||
TC_GetStatus(TC0, 0);
|
TC_GetStatus(TC0, 0);
|
||||||
// variables used to determine if the corresponding button is pressed
|
// variables used to determine if the corresponding button is pressed
|
||||||
bool buttonPressedPlus = (digitalRead(buttonPlusPin) == LOW);
|
bool buttonPressedOne = (digitalRead(buttonOnePin) == LOW);
|
||||||
bool buttonPressedMinus = (digitalRead(buttonMinusPin) == LOW);
|
bool buttonPressedTwo = (digitalRead(buttonTwoPin) == LOW);
|
||||||
|
|
||||||
// handles the plus button
|
// handles the plus button
|
||||||
if (buttonPressedPlus){
|
if (buttonPressedOne){
|
||||||
++timesPressedPlus;
|
++timesPressedOne;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (increased) {
|
if (increased) {
|
||||||
increased = false;
|
increased = false;
|
||||||
}
|
}
|
||||||
timesPressedPlus = 0 ;
|
timesPressedOne = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handles the minus button
|
// handles the minus button
|
||||||
if (buttonPressedMinus){
|
if (buttonPressedTwo){
|
||||||
++timesPressedMinus;
|
++timesPressedTwo;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (decreased) {
|
if (decreased) {
|
||||||
decreased = false;
|
decreased = false;
|
||||||
}
|
}
|
||||||
timesPressedMinus = 0 ;
|
timesPressedTwo = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// increases counter if button has been pressed long enough
|
// increases counter if button has been pressed long enough
|
||||||
if (timesPressedPlus >= compareValue) {
|
if (timesPressedOne >= compareValue) {
|
||||||
if (!increased) {
|
if (!increased) {
|
||||||
increment();
|
increment();
|
||||||
}
|
}
|
||||||
increased = true;
|
increased = true;
|
||||||
timesPressedPlus = 0;
|
timesPressedOne = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decreases counter if button has been pressed long enough
|
// decreases counter if button has been pressed long enough
|
||||||
if (timesPressedMinus >= compareValue) {
|
if (timesPressedTwo >= compareValue) {
|
||||||
if (!decreased) {
|
if (!decreased) {
|
||||||
decrement();
|
decrement();
|
||||||
}
|
}
|
||||||
decreased = true;
|
decreased = true;
|
||||||
timesPressedMinus = 0;
|
timesPressedTwo = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user