Hello everyone! Last Friday I ordered my first Arduino and of course I tried it out right away I'm currently still working on the basics and would like to familiarize myself a little with the technology and C++. However, I wanted to detach myself from the ready-made sketches and program a part myself (for a better understanding), unfortunately it doesn't quite work yet, but I don't see the error either. I want when I press the zero button on the IR remote that an LED light on the breadboard comes on and presses it again to turn it off. Instead of the switch-case query, I would like to make an if query, because I'm used to it from Java. However, when I press the 0 button on the RC with the given code, the lamp does not turn on.
Maybe someone knows where I'm wrong?
Regards Marcel
Code:
#include <IRremote.h>
#include <IRremoteInt.h>
int receiverPin = 11;
int led = 7;
//int isOn[] = {0}; Alternative über Array bei mehreren Lampen
boolean isOn = true;
IRrecv meinReceiver(receiverPin); //Receiver hinzufügren und Pin zuweisen
decode_results results;
#define tasteNull 16738455 //Überall im Code, wo "tasteNull" vorkommt, wird der Text durch 16738455 ersetzt
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
meinReceiver.enableIRIn();
}
void loop() {
if(meinReceiver.decode(&results)){
Serial.println(results.value, DEC);
unsigned int wertFB = results.value;
if(wertFB == tasteNull){
if(isOn == false){
digitalWrite(led, HIGH);
isOn = true;
}else{
digitalWrite(led, LOW);
isOn = false;
}
}
meinReceiver.resume(); //Ruft Funktion der Klasse IRremote auf
}
}
Hallo an alle! Letzten Freitag habe ich mir meinen ersten Arduino bestellt und habe ihn dementsprechend natürlich gleich ausprobiert Aktuell bin in ich noch bei den Basics und möchte mich erstmal ein wenig mit der Technik und C++ vertraut machen. Von den Vorgefertigten Sketches wollte ich mich jedoch etwas ablösen und einen Teil selbst programmieren (zum besseren Verständnis), leider klappt das noch nicht so ganz, allerdings sehe ich auch den Fehler nicht. Ich möchte, wenn ich die Taste Null auf der IR-Fernbedienung drücke, dass eine LED Lampe auf dem Breadboard an geht und bei erneutem drücken wieder aus geht. Anstelle der switch-case Abfrage möchte ich aber eine if-Abfrage machen, da ich es so von Java gewohnt bin. Wenn ich mit dem angegebenen Code auf die Taste 0 der FB drücke, schaltet sich die Lampe jedoch nicht an.
Vielleicht weiß ja jemand, wo ich meinen Denkfehler habe?
LG Marcel