Hallo habe 4 led lichter auf pin 13,12,11,10 möchte die das die LEDs für eine bestimmte zeit an aus schalten kann.
led_t leds[] = {
{ 13, 20000, },
{ 12, 20000, },
{ 11, 20000, },
{ 10, 20000, },
#define NUMLEDS (sizeof(leds)/sizeof(leds[0]))
const int ledPin = 13;12;11;10;// the pin that the LED is attached to - change this if you have a separate LED connected to another pin
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
Ich habe 4 LEDs ich möchte alle 4 LED gleichzeitig automatische ein und ausschalten lassen für eine bestimmte Zeit "x", die ich definieren möchte. Also sowas wie ein Timer in etwa ?
Longbardo:
Ich habe 4 LEDs ich möchte alle 4 LED gleichzeitig automatische ein und ausschalten lassen für eine bestimmte Zeit "x", die ich definieren möchte. Also sowas wie ein Timer in etwa ?
Dafür ist dein obiger Sketch nicht geeignet.
Wie schon vorgeschlagen, sieh die "BlinkWithoutDelay" an.
Das ist dafür geeignet und die Zeit kannst du auch einstellen.
Hier noch ein kurzes Beispiel mit dem du es testen kannst.
Der Taster sollte entprellt werden.
Das geht per Hardware oder Software (debounce).
Die Leuchtzeit kannst du in "OnTime" einstellen.
Der Sketch dient als Orientierung und kann sicher optimiert werden.
Bei mir seht jetzt Sketch wird kompiliert..... darunter steht nun
Die Build-Voreinstellungsdatei konnte nicht geschrieben werden
java.io.FileNotFoundException: /var/folders/gz/zdvq2r1j727dyq0zkpl848ym0000gr/T/build2553752469290924910.tmp/BlinkWithoutDelay.cpp (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.(FileOutputStream.java:213)
at java.io.FileOutputStream.(FileOutputStream.java:162)
at processing.app.debug.Compiler.preprocess(Compiler.java:1268)
at processing.app.debug.Compiler.preprocess(Compiler.java:1228)
at processing.app.debug.Compiler.compile(Compiler.java:358)
at processing.app.debug.Compiler.build(Compiler.java:121)
at processing.app.Sketch.build(Sketch.java:1109)
at processing.app.Sketch.exportApplet(Sketch.java:1127)
at processing.app.Sketch.exportApplet(Sketch.java:1113)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
at processing.app.debug.Compiler.adviseDuplicateLibraries(Compiler.java:477)
at processing.app.debug.Compiler.build(Compiler.java:128)
at processing.app.Sketch.build(Sketch.java:1109)
at processing.app.Sketch.exportApplet(Sketch.java:1127)
at processing.app.Sketch.exportApplet(Sketch.java:1113)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
at java.lang.Thread.run(Thread.java:745)
Hallo,
für eine (1 Stck) LED- und noch eine (1 Stck) LED.
// each "event" (LED) gets their own tracking variable
unsigned long previousMillisTonLED=0;
unsigned long previousMillisPauseLED=0;
// different intervals for each LED
int intervalTonLED = 500;
int intervalPauseLED = 1000;
// each LED gets a state varaible
boolean PauseLEDstate = false; // the LED will turn ON in the first iteration of loop()
boolean TonLEDstate = false; // need to seed the light to be OFF
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop() {
// get current time stamp
// only need one for both if-statements
unsigned long currentMillis = millis();
// time to toggle LED on Pin 12?
if ((unsigned long)(currentMillis - previousMillisTonLED) >= intervalTonLED) {
TonLEDstate = !TonLEDstate;
digitalWrite(12, TonLEDstate);
// save current time to pin 12's previousMillis
previousMillisTonLED = currentMillis;
}
// time to toggle LED on Pin 13?
if ((unsigned long)(currentMillis - previousMillisPauseLED) >= intervalPauseLED) {
PauseLEDstate = !PauseLEDstate;
digitalWrite(13, PauseLEDstate);
// save current time to pin 12's previousMillis
previousMillisPauseLED = currentMillis;
}
}