Hier der Link zum Experiment der genauen Zeitmessung:
Und was soll uns dieses Posting sagen?
GruĂ Tommy
Ich tippe auf ein Suchspiel: Wo ist der Arduino versteckt ?
Oder einfacher: Spam
GruĂ Tommy
Oder falsches Forum erwischt?
Hallo,
Thema ist zwar OT allerdings fand ich es ganz gut mal wieder in die Physik dazu einzusteigen.
GruĂ Heinz
1 Like
Das ist ja auch ok....aber dann muĂ der TO auch ein paar Informationen hier zu im Forum schreiben und das nicht einfach nur so reinkippen.
Nicht so genau, aber preiswert...
// Using interrupts - detect FALLING
volatile bool buttonPressed2, buttonPressed3; // "volatile" inside interrupt service routeine (ISR)
int buttonPin2 = 2; // INT0
int buttonPin3 = 3; // INT1
int ledPin4 = 4; // GRN LED
int ledPin5 = 5; // RED LED
unsigned long startTime, stopTime;
bool firstRead2 = 1, firstRead3 = 1;
void setup() {
Serial.begin(115200); // start serial monitor
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin2), buttonISR2, FALLING); // PIN#, ISR, TRIGGER
attachInterrupt(digitalPinToInterrupt(buttonPin3), buttonISR3, FALLING);
}
void loop() {
checkButton2();
checkButton3();
}
int buttonISR2() {
noInterrupts(); // disable interrupts in ISR
buttonPressed2 = true; // set flag
interrupts(); // enable interrupts
}
int buttonISR3() {
noInterrupts();
buttonPressed3 = true;
interrupts();
}
void checkButton2() {
if (buttonPressed2 && firstRead2) {
startTime = micros();
firstRead2 = 0;
digitalWrite(ledPin4, HIGH);
}
}
void checkButton3() {
if (buttonPressed3 && firstRead3) {
stopTime = micros();
firstRead3 = 0;
digitalWrite(ledPin5, HIGH);
Serial.print("Start: ");
Serial.println(startTime);
Serial.print(" Stop: ");
Serial.println(stopTime);
Serial.print("Split: ");
Serial.println(stopTime - startTime);
delay(500);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
Serial.println("Press RESET button.");
}
}
diagram.json for wokwi.com
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": 4.8, "left": -0.5, "attrs": {} },
{
"type": "wokwi-led",
"id": "led1",
"top": -58.8,
"left": 49.4,
"rotate": 270,
"attrs": { "color": "red", "flip": "1" }
},
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": -51.4,
"left": 134.4,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": -106.8,
"left": 49.4,
"rotate": 270,
"attrs": { "color": "green", "flip": "1" }
},
{
"type": "wokwi-pushbutton",
"id": "btn2",
"top": -99.4,
"left": 134.4,
"attrs": { "color": "green" }
},
{
"type": "wokwi-text",
"id": "legendservo1",
"top": -96,
"left": 201.6,
"attrs": { "text": "START" }
},
{
"type": "wokwi-text",
"id": "legendservo2",
"top": -48,
"left": 201.6,
"attrs": { "text": "STOP" }
}
],
"connections": [
[ "nano:GND.2", "led1:C", "black", [ "v0" ] ],
[ "nano:GND.2", "btn1:1.l", "black", [ "v0" ] ],
[ "nano:GND.2", "led2:C", "black", [ "v0" ] ],
[ "nano:GND.2", "btn2:1.l", "black", [ "v0" ] ],
[ "nano:5", "led1:A", "green", [ "v0" ] ],
[ "nano:4", "led2:A", "green", [ "v0" ] ],
[ "nano:2", "btn2:2.l", "green", [ "v0" ] ],
[ "nano:3", "btn1:2.l", "green", [ "v0" ] ]
],
"dependencies": {}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.