Skip to content

Instantly share code, notes, and snippets.

@michaelsarduino
Last active September 3, 2015 19:25
Show Gist options
  • Save michaelsarduino/6334bf00be2ea0f24900 to your computer and use it in GitHub Desktop.
Save michaelsarduino/6334bf00be2ea0f24900 to your computer and use it in GitHub Desktop.
#include <SoftPWM.h>
#include <SoftPWM_timer.h>
int status_pin = 1;
int richtung = 1;
boolean bewegung = false;
int counter = 0;
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
Serial.begin(9600);
attachInterrupt(0, motion, FALLING); //definieren eines Interrupts an Interruptpin 0 (Arduino Pin 2)
SoftPWMBegin();
SoftPWMSet(13, 0); //LED des Arduino zum Zeigen der aktuellen Werte
}
void loop() {
if(bewegung) {
if(richtung)
{
counter = counter + 1;
}
else {
counter = counter -1;
}
SoftPWMSet(13, counter);
Serial.println(counter);
} //auslesen der Werte und hoch-/runterzaehlen
bewegung = false;
}
void motion() {
status_pin = digitalRead(2);
if(status_pin == digitalRead(3)) //wenn status gleich(beide low), dann pin 3 zuerste, also richtung 1, wenn unterschiedlich pin 2 zuerst, also richtung 0
{
richtung = 1;
}
else {
richtung = 0;
}
bewegung = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment