Arduino Code funktioniert nicht?

IRremote und JoyStick funktionieren nicht

#include <SPI.h> // Bibliothek für SPI-Kommunikation

#include <Mirf.h> // Bibliothek für nRF24L01

#include <nRF24L01.h> // Treiber für nRF24L01

#include <MirfHardwareSpiDriver.h> // Hardware-SPI-Treiber für Mirf

#include <IRremote.h> // Bibliothek für IR-Kommunikation

// Pin-Definitionen

int receiver = 4; // Pin für den IR-Empfänger

const int SW = 2; // Pin für den Schalter

const int X = A0; // Analog-Pin für X-Achse

const int Y = A1; // Analog-Pin für Y-Achse

// Initialisierung des IR-Empfängers

IRrecv irrecv(receiver);

IRsend results;

uint32_t last_decodedRawData = 0; // Variable zum Speichern des letzten IR-Codes

// Funktion zur Verarbeitung des empfangenen IR-Codes

void translateIR() {

 if (irrecv.decodedIRData.flags) {

  // Wenn ein Wiederholungscode empfangen wird, den letzten empfangenen Code verwenden

  irrecv.decodedIRData.decodedRawData = last_decodedRawData;

 } else {

  // Den empfangenen Code im seriellen Monitor ausgeben

  Serial.print("Empfangener IR-Code: 0x");

  Serial.println(irrecv.decodedIRData.decodedRawData, HEX);

 }

}

// Setup-Funktion, die einmal beim Starten des Programms ausgeführt wird

void setup() {

 Serial.begin(9600); // Startet die serielle Kommunikation mit 9600 Baud

 irrecv.enableIRIn(); // Aktiviert den IR-Empfänger

 pinMode(SW, INPUT); // Setzt den Schalter-Pin als Eingang

 digitalWrite(SW, HIGH); // Aktiviert den Pull-up-Widerstand für den Schalter

 Mirf.cePin = 9; // Setzt den Chip Enable (CE) Pin für den nRF24L01

 Mirf.csnPin = 10; // Setzt den Chip Select Not (CSN) Pin für den nRF24L01

 Mirf.spi = &MirfHardwareSpi; // Setzt den SPI-Treiber für Mirf

 Mirf.init(); // Initialisiert den nRF24L01

 Mirf.setRADDR((byte *)"Sen01"); // Setzt die Adresse des Senders

 Mirf.payload = sizeof(unsigned int); // Setzt die Payload-Größe auf die Größe eines unsigned int

 Mirf.channel = 3; // Setzt den Kommunikationskanal auf 3

 Mirf.config(); // Konfiguriert den nRF24L01

}

unsigned int adata = 0; // Variable zum Speichern der zu sendenden Daten

// Hauptschleife, die kontinuierlich ausgeführt wird

void loop() {

 // Überprüfen, ob ein IR-Signal empfangen wurde

 if (irrecv.decode()) {

  translateIR(); // Verarbeitung des empfangenen IR-Codes

  irrecv.resume(); // Bereit zum Empfang des nächsten IR-Codes

 }

 // Lesen des Schalter- und Analogwerte

 int swValue = digitalRead(SW); // Lesen des Schalterzustands

 int xValue = analogRead(X); // Lesen des X-Achsen-Werts

 int yValue = analogRead(Y); // Lesen des Y-Achsen-Werts

 // Überprüfen der empfangenen IR-Codes und Setzen von adata entsprechend

 if (last_decodedRawData == 0xAD52FF00) {

  adata = 12006;

 } else if (last_decodedRawData == 0xBF40FF00) {

  adata = 12005;

 } else if (last_decodedRawData == 0xBC43FF00) {

  adata = 12004;

 } else if (last_decodedRawData == 0xBB44FF00) {

  adata = 12003;

 }

 // Überprüfen des Schalterwerts und Setzen von adata

 if (swValue == 0) {

  adata = 2103;

 }

 // Überprüfen der Analogwerte und Setzen von adata

 if (yValue < 1024 && yValue > 6 && xValue > 150 && xValue < 800) {

  adata = 213;

 } else if (yValue < 512 && yValue > -1 && xValue > 200 && xValue < 700) {

  adata = 312;

 } else if (xValue < 509 && xValue > -1 && yValue > 200 && yValue < 750) {

  adata = 231;

 } else if (xValue < 1024 && xValue > 515 && yValue > 450 && yValue < 750) {

  adata = 321;

 } else if (xValue < 514 && xValue > 510 && yValue < 511 && yValue > 507) {

  adata = 123;

 }

 // Senden der Daten über Mirf, wenn adata gesetzt wurde

 if (adata != 0) {

  byte data[Mirf.payload]; // Array zum Speichern der zu sendenden Daten

  data[0] = adata & 0xFF; // Niedriges Byte von adata

  data[1] = adata >> 8; // Hohes Byte von adata

  Mirf.setTADDR((byte *)"Rec01"); // Setzt die Adresse des Empfängers

  Mirf.send(data); // Sendet die Daten

  while (Mirf.isSending()) {} // Warten, bis das Senden abgeschlossen ist

  delay(20); // Kurze Pause, um das Senden zu beenden

  adata = 0; // Zurücksetzen von adata nach dem Senden

 }

}

Arduino, Code, Programmiersprache, Arduino Uno, Arduino IDE
Arduino 32 Segment Display Counter programmieren?

Hi,

wie kann ich bei einem Arduino 32 Segment Display einen Counter programmieren der von 9 auf 0 runter geht? Ich habe mir zuerst dieses Standart BSP von `Hello World `: Das ist der Script:

/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Motor startet in:");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(8,2);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}

Danke im voraus :-).

programmieren, Arduino, Arduino Uno

Meistgelesene Beiträge zum Thema Arduino Uno