mirror of
https://github.com/2martens/uni.git
synced 2026-05-06 19:36:26 +02:00
[ES] Blatt 1 und 2 hinzugefügt
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
102
es/blatt2/uebung2-1/uebung2-1.ino
Normal file
102
es/blatt2/uebung2-1/uebung2-1.ino
Normal file
@ -0,0 +1,102 @@
|
||||
int ledPin = 7;
|
||||
int buttonPlusPin = 5;
|
||||
int buttonMinusPin = 3;
|
||||
int volatile counter = 0;
|
||||
int timesPressedPlus = 0;
|
||||
int timesPressedMinus = 0;
|
||||
int vergleichswert = 60;
|
||||
int rc = 10499;
|
||||
boolean increased = false;
|
||||
boolean decreased = false;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
|
||||
pmc_set_writeprotect(false);
|
||||
pmc_enable_periph_clk(ID_TC0);
|
||||
|
||||
// Hier erfolgt die Konfiguration des Timers
|
||||
TC_Configure(TC0, 0, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK2) ;
|
||||
TC_SetRC(TC0, 0, rc);
|
||||
|
||||
TC0->TC_CHANNEL[0].TC_IER=TC_IER_CPCS; // IER = interrupt enable register
|
||||
TC0->TC_CHANNEL[0].TC_IDR=~TC_IER_CPCS;
|
||||
|
||||
NVIC_ClearPendingIRQ(TC0_IRQn);
|
||||
NVIC_EnableIRQ(TC0_IRQn);
|
||||
|
||||
// Hier wird der konfigurierte Timer gestartet
|
||||
TC_Start(TC0, 0);
|
||||
|
||||
// Hier werden die Taster konfiguriert
|
||||
pinMode(buttonPlusPin, INPUT);
|
||||
pinMode(buttonMinusPin, INPUT);
|
||||
|
||||
// Ausgabe über den seriellen Port
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
// Hier wird die Plus Taste abgefragt
|
||||
analogWrite(ledPin, counter);
|
||||
Serial.print("LED: ");
|
||||
Serial.println(counter);
|
||||
}
|
||||
|
||||
void increment() {
|
||||
if (counter < 255) {
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void decrement() {
|
||||
if (counter > 0) {
|
||||
counter -= 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TC0_Handler()
|
||||
{
|
||||
TC_GetStatus(TC0, 0);
|
||||
boolean tasteGedruecktPlus = (digitalRead(buttonPlusPin) == LOW);
|
||||
boolean tasteGedruecktMinus = (digitalRead(buttonMinusPin) == LOW);
|
||||
|
||||
if (tasteGedruecktPlus){
|
||||
++timesPressedPlus;
|
||||
}
|
||||
else {
|
||||
if (increased) {
|
||||
increased = false;
|
||||
}
|
||||
timesPressedPlus = 0 ;
|
||||
}
|
||||
|
||||
if (tasteGedruecktMinus){
|
||||
++timesPressedMinus;
|
||||
}
|
||||
else {
|
||||
if (decreased) {
|
||||
decreased = false;
|
||||
}
|
||||
timesPressedMinus = 0 ;
|
||||
}
|
||||
|
||||
if (timesPressedPlus >= vergleichswert) {
|
||||
if (!increased) {
|
||||
increment();
|
||||
}
|
||||
increased = true;
|
||||
timesPressedPlus = 0;
|
||||
}
|
||||
|
||||
// Hier wird die Minus Taste abgefragt
|
||||
if (timesPressedMinus >= vergleichswert) {
|
||||
if (!decreased) {
|
||||
decrement();
|
||||
}
|
||||
decreased = true;
|
||||
timesPressedMinus = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user