Hallo,
ich stehe am Anfang meiner Weiterbildung zum Techniker und bin gerade dabei einen Prüfstand für ABS-Sensoren zu bauen.
Ich versuche einen Sketch zu schreiben für den Arduino Uno.
Ich habe:
2Taster
3 Led´s
1 Motor
Es soll 3 Stufen geben.
Stufe 1: 1Led und ein PWM Signal am Motor
Stufe 2: 2Led´s und PWM
Stufe 3: 3Led´s...
Nach der 3.Stufe soll es nicht weiter hoch gehen egal wie oft ich den Taster für hoch drücke.
Taster runter soll natürlich die Stufen runter schalten bis 0
Ich habe einen externen Pulldown widerstand an die Taster gelegt.
Der Sketch ist im Anhang...
Wäre klasse wenn jemand sich das mal anschauen könnte damit ich für die nächsten Projekte was draus lernen kann.
Gruß Lars
// constants won't change. They're used here to
// set pin numbers:
const int tasterHoch = 2; // the number of the pushbutton pin
const int tasterRunter = 3; // the number of the pushbutton pin
const int ledPin1 = 11; // the number of the LED pin
const int ledPin2 = 12; // the number of the LED pin
const int ledPin3 = 13; // the number of the LED pin
const int MotorPin = 6; // the number of the LED pin
int zaehler = 0;
int buttonStateH = 0;
int buttonStateD = 0;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(MotorPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(tasterHoch, INPUT);
pinMode(tasterRunter, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonStateH = digitalRead(tasterHoch);
buttonStateD = digitalRead(tasterRunter);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonStateH == HIGH) {
delay(5);
if (buttonStateH) {
if (buttonState == LOW)
{
if (buttonState) {
zaehler ++;
}
}
}
}
if (buttonStateD == HIGH) {
delay(5);
if (digitalRead(tasterRunter)) {
if (buttonState == LOW)
{
if (digitalRead(tasterRunter)) {
zaehler --;
}
}
}
}
zaehler = min (3 , zaehler);
zaehler = max (0 , zaehler);
// *********************************************************** zaehler = 0 ****************************
if (zaehler == 0) {
digitalWrite (ledPin1, LOW);
digitalWrite (ledPin2, LOW);
digitalWrite (ledPin3, LOW);
analogWrite (MotorPin, 0);
}
// *********************************************************** zaehler = 1 ****************************
if (zaehler == 1) {
digitalWrite (ledPin1, HIGH);
digitalWrite (ledPin2, LOW);
digitalWrite (ledPin3, LOW);
analogWrite (MotorPin, 100);
}
// *********************************************************** zaehler = 2 ****************************
if (zaehler == 2) {
digitalWrite (ledPin1, HIGH);
digitalWrite (ledPin2, HIGH);
digitalWrite (ledPin3, LOW);
analogWrite (MotorPin, 150);
}
// *********************************************************** zaehler = 3 ****************************
if (zaehler == 3) {
digitalWrite (ledPin1, HIGH);
digitalWrite (ledPin2, HIGH);
digitalWrite (ledPin3, HIGH);
analogWrite (MotorPin, 200);
}
}
Button_Hammes2.ino (2.85 KB)