Wie kann man den Arduino UNO für drei Lampen programmieren?

2 Antworten

Hallo

da ich blutiger Anfänger bei der Arduino progammierung bin, habe ich die ganzen blocks genommen und ein und aus geschaltet.

Idiotensicher so zu sagen. aber du kannst alle weglassen, die gerade nicht geschaltet weden sollen.

Hier ein Beispiel mit 13 Reihen a 10 LEDs

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led_01 = 1;
int led_02 = 2;
int led_03 = 3;
int led_04 = 4;
int led_05 = 5;
int led_06 = 6;
int led_07 = 7;
int led_08 = 8;
int led_09 = 9;
int led_10 = 10;
int led_11 = 11;
int led_12 = 12;
int led_13 = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led_01, OUTPUT);
pinMode(led_02, OUTPUT);
pinMode(led_03, OUTPUT);
pinMode(led_04, OUTPUT);
pinMode(led_05, OUTPUT);
pinMode(led_06, OUTPUT);
pinMode(led_07, OUTPUT);
pinMode(led_08, OUTPUT);
pinMode(led_09, OUTPUT);
pinMode(led_10, OUTPUT);
pinMode(led_11, OUTPUT);
pinMode(led_12, OUTPUT);
pinMode(led_13, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(1000);

digitalWrite(led_01, 1);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 1);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 1);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 1);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 1);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 1);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 1);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 1);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 1);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 1);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 1);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 1);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 0);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 0);

delay(83);

digitalWrite(led_01, 1);
digitalWrite(led_02, 0);
digitalWrite(led_03, 0);
digitalWrite(led_04, 0);
digitalWrite(led_05, 0);
digitalWrite(led_06, 0);
digitalWrite(led_07, 0);
digitalWrite(led_08, 0);
digitalWrite(led_09, 0);
digitalWrite(led_10, 0);
digitalWrite(led_11, 0);
digitalWrite(led_12, 0);
digitalWrite(led_13, 1);

delay(30000);

}

Zuerst hoffe ich, dass du keine Glühbirne angeschlossen hast, denn das könnte unter Umständen dazu führen, dass durch den zu hohen Strom, den die Glühbirne zieht, der Ausgang des Arduino abraucht.

du schreibst auch nicht, was nicht funktioniert. Blinken beim Anschluss der dritten (hoffentlich) LED gar keine der anderen mehr, oder nur die dritte nicht? Warum hast du für Grün und Gelb jeweils zwei Variablen und Pins vorgesehen? Das verwirrt und könnte dazu geführt haben, dass du zwar Pin 10 auf HIGH setzt, die LED aber an Pin 9 angeschlossen hast.

Der Code sollte funktionieren, wenn du alles richtig angeschlossen hast und auch LEDs und keine Glühbirnen verwendest.

Code Funktioniert auch... habe nur vergessen den pinMode für die OUTPUTs zu setzen (facepalm)

0

Wieso funktioniert dieser zufallsgenerator bei Arduino nicht?

Hallo zusammen!

Ich möchte bei einer Rennautobahn eine Ampel bauen. Um es spannender zu gestalten möchte ich, das die letzte LED nach einer zufällig gewählten Zeit (zwischen 1 und 4 sekunden) . Zum steuern verwende ich einen Arduino Mega und zum programmieren das Arduino Programm. das nachfolgende Programm haben ich schon in C# getestet und dort funktioniert es, nur leider nicht im Arduino Programm.

const int intRot13 = 1;
const int intRot12 = 2;
const int intRot11 = 3;
const int intRot10 = 4;
const int intRot9 = 5;

void setup()
{
  pinMode(intRot13, OUTPUT);
  pinMode(intRot12, OUTPUT);
  pinMode(intRot11, OUTPUT);
  pinMode(intRot10, OUTPUT);
  pinMode(intRot9, OUTPUT);
}

void Zufall(byte bytAmpel)
{
 int Zahl1 = 0;
 random Rnd = new random();
 Zahl1 = Rnd.Next(1000, 4000)
}

void loop()
{
  digitalWrite(1, HIGH);
  delay(1500);
  digitalWrite(2, HIGH);
  delay(1500);
  digitalWrite(3, HIGH);
  delay(1500);
  digitalWrite(4, HIGH);
  delay(1500);
  digitalWrite(5, HIGH);
  delay(Zufall());
  delay (3000);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
}

Wäre für jede Hilfe dankbar!

...zur Frage

Was ist an diesem Arduino programm falsch?

void setup() { pinMode(13, OUTPUT); pinMode(12, INPUT); }

void loop() { if ( 12 = HIGH) digitalWrite(13, HIGH); }

Fehlermeldung: Arduino: 1.6.8 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users-----------\Desktop\Arduino Projekte\IF_Befehl_Test\IF_Befehl_Test.ino: In function 'void loop()':

IF_Befehl_Test:7: error: lvalue required as left operand of assignment

if (12 = HIGH) digitalWrite(13, HIGH);

    ^

exit status 1 lvalue required as left operand of assignment

Dieser Bericht wäre detaillierter, wenn die Option "Ausführliche Ausgabe während der Kompilierung" in Datei -> Voreinstellungen aktiviert wäre.

...zur Frage

Arduino HR-S04 Entfernungsmesser misst nicht korrekt?

Hallo,

Ich habe einen Arduino UNO und habe mir einen Entfernungsmesser (HR-S04) angeschlossen, ich habe das ganze programmiert und will nun auf dem Seriellen Monitor anzeigen lassen, wie viele cm die Entfernung beträgt. Wenn ich nun den Seriellen Monitor starte und den Entfernungsmesser irgendeine Distanz messen lasse, wird dort immer ein Wert über 18000cm angezeigt, das kann grundsätzlich nicht stimmen, es wäre nett, wenn ihr mir helfen würdet! :D (Bilder dazu und Code sind unten)

Das ist mein Code:

long laenge;

long cm;

void setup() 

{

 Serial.begin (9600);

 pinMode(7,OUTPUT);

 pinMode(8,INPUT);

}

void loop() 

{

 digitalWrite(7,LOW);

 delayMicroseconds(2);

 digitalWrite(7,HIGH);

 delayMicroseconds(5);

 digitalWrite(7,LOW);

 laenge = pulseIn(8,HIGH);

 Serial.print(cm);

 Serial.println("cm");

cm=laenge; //Ich weiß, dass ich an dieser Stelle warscheinlich etwas ändern muss, ich weiß nur nicht was...

 delay(1000);

}

Mfg Alex

...zur Frage

Was möchtest Du wissen?