Hilfe bei millis()
hallo, ich habe ein kleines problem mit der millis() funktion. eine einzelne millis() anwendung bekomme ich hin, auch habe ich den sinn verstanden. das mir jetzt probleme bereitet, ich komme nicht mehrere zum laufen. ich habe den code eingefügt und möchete nun die delays raus haben und durch millis ersetzen. es sollen 2 verschiedene zeitvariablen genutzt werden. der 1. code funktioniert aber im 2. code geht gar nichts(ist zum testen gedacht
).
es soll auch immer einen art <notaus> geben, zum abbrechen der schleife.
1.code
2. code ( die variablen sind gleich..)
wo liegt nun mein denk fehler :~
gruß marco
![smiley :)](https://forum.arduino.cc/smileys/arduino/smiley.gif)
es soll auch immer einen art <notaus> geben, zum abbrechen der schleife.
1.code
code: [select]
#include <bounce.h>
#include <liquidcrystal.h>
#include <encoder.h>
liquidcrystal lcd(17, 4, 5, 6, 7, 8); // lcd
encoder myenc (15, 16); // encoder
int kamerapin = 3; //kamera auslöser optokopler
int motor1pin = 0 ; //slidermotor vorwärts//
int motor2pin = 18 ; //slidermotor rückwärts//
int motorsteuerungpin = 11 ; //slider geschwindigkeit//
int encoderknopfpin = 1 ; // encoder bushbutton //
int menueknopfpin = 9; // menueauswahl schalter s1//
int zurueckknopfpin = 10 ; // zruückschalter s2//
int akkupin = a5 ; // akku ladezustand messen//
int interzeit = 0; // encoderintervallzeit//
bounce startknopf = bounce(encoderknopfpin, 50);
bounce menueknopf = bounce(menueknopfpin, 50);
bounce zurueckknopf = bounce(zurueckknopfpin, 50);
int zaehler1 = 0;
int zaehler2 = 0;
int zaehler3 = 0;
int akkuwert = 0; // akku spannug a5//
//int akkuausgabe = 0; //akku ausgabe wert für lcd//
unsigned long vorher; //zeitwert 0 aufnahme
unsigned long vorher1; // zeitwert 1 aufnahme
unsigned long vorher2; // zeitwert 2 aufnahme
int ausloe = 0; // auslösung
int intervall [] = { 100, 1000, 2000, 5000, 10000 }; // intervall kameraauslösung zeit
int kamerastatus = low;
int sliderstatus = low;
void setup()
{ pinmode(kamerapin, output);
pinmode(motor1pin, output);
pinmode(motor2pin, output);
pinmode(motorsteuerungpin, output);
pinmode(encoderknopfpin, input);
pinmode(menueknopfpin, input);
pinmode(zurueckknopfpin, input);
pinmode(akkupin, input);
vorher = 0;
lcd.begin(16, 2);
//serial.begin(9600);
lcd.print( "fototimer mk 600");
delay(2000);
lcd.clear();
}
long position = -999;
void loop()
{
akkuwert = analogread(akkupin);
float v = akkuwert * ( 12.0 / 1023.0);
lcd.setcursor(10, 0);
lcd.print(v);
lcd.setcursor(15, 0);
lcd.print("v");
long newpos = (myenc.read())/4;
if (newpos != position) {
position = newpos; }
menueknopf.update (); //update für menüknopf-auswahl//
int menuewert = menueknopf.read();
zurueckknopf.update ();
int zurueckwert = zurueckknopf.read();
zurueckwert++;
startknopf.update();
int startwert = startknopf.read();
if(startwert == high)
zaehler1++;
if(startwert == 1)
{
for(int = 1; < 400; i++)
{
lcd.setcursor(0,1);
lcd.print(i);
lcd.print(" foto ");
digitalwrite(kamerapin, high);
delay(500);
digitalwrite(kamerapin, low);
delay(newpos * 1000);
}
}
lcd.setcursor(0,0);
lcd.print(newpos);
lcd.print( " zeit ");
zaehler1 = zaehler1%4;
}
2. code ( die variablen sind gleich..)
code: [select]
long position = -999;
void loop()
{
akkuwert = analogread(akkupin);
float v = akkuwert * ( 12.0 / 1023.0);
lcd.setcursor(10, 1);
lcd.print(v);
lcd.setcursor(15, 1);
lcd.print("v");
menueknopf.update (); //update für menüknopf-auswahl//
int menuewert = menueknopf.read();
zurueckknopf.update ();
int zurueckwert = zurueckknopf.read();
zurueckwert++;
startknopf.update();
int startwert = startknopf.read();
if(startwert == high)
zaehler1++;
if(menuewert == high)
zaehler1++;
long newpos = (myenc.read())/4;
if (newpos != position) {
position = newpos; }
switch(zaehler1)
{
case 0: lcd.setcursor(0, 0);
lcd.print( "menue test");
lcd.setcursor(1, 6);
lcd.print(position);
break;
case 1:
lcd.setcursor(0, 0);
lcd.print("foto 400");
if((millis() - vorher1) > intervall[2])
{
vorher1 = millis();
kamerastatus = !kamerastatus;
digitalwrite(kamerapin, kamerastatus);
zaehler2++;
}
ausloe = (zaehler2 / 2);
lcd.setcursor(1, 4);
lcd.print(ausloe);
break;
case 2 :
lcd.setcursor(0, 0);
lcd.print( "hdr 7");
if((millis() - vorher1) > 1000)
{
sliderstatus =!sliderstatus;
digitalwrite(motor2pin, sliderstatus);
if(zurueckwert == 1)
break;
}
if((millis() - vorher2) > 1000)
{
vorher2 = millis();
kamerastatus = !kamerastatus;
digitalwrite(kamerapin, kamerastatus);
}
break;
case 3 :
lcd.setcursor(0, 0);
lcd.print( "foto 400 slider");
if((millis() - vorher1) > intervall[2])
{
kamerastatus = !kamerastatus;
digitalwrite(kamerapin, kamerastatus);
zaehler3++;
}
if((millis() - vorher1) > intervall[2])
{
sliderstatus =!sliderstatus;
digitalwrite(motor2pin, sliderstatus);
}
ausloe = (zaehler3 / 2);
lcd.setcursor(1, 4);
lcd.print(ausloe);
break;
}
zaehler1 = zaehler1 % 4;
}
wo liegt nun mein denk fehler :~
gruß marco
code: [select]
menueknopf.update (); //update für menüknopf-auswahl//
int menuewert = menueknopf.read();
zurueckknopf.update ();
int zurueckwert = zurueckknopf.read();
zurueckwert++;
startknopf.update();
int startwert = startknopf.read();
if(startwert == high)
zaehler1++;
if(menuewert == high)
zaehler1++;
diese zähler mußt du alle mittels l-h flanke (oder h-l flanke falls du einen pullupwiderstand verwendest) erhöhen, nicht mittels zustand des tasterpins damit ein tastendruck die zählerwariable nur einmal erhöht. siehe http://electronics.flosscience.com/home_le/arduino-lessons/toggle-on-and-off
code: [select]
case 1:
lcd.setcursor(0, 0);
lcd.print("foto 400");
if((millis() - vorher1) > intervall[2])
{
vorher1 = millis();
kamerastatus = !kamerastatus;
digitalwrite(kamerapin, kamerastatus);
zaehler2++;
}
ausloe = (zaehler2 / 2);
lcd.setcursor(1, 4);
lcd.print(ausloe);
break;
du mußt die logik des switch case bedingung ändern.
der startknopf darf nicht die switch variable ändern sondern die switch case aktivieren, da ansonsten das foto dauernd ausgelöst wird.
bitte beschreibe wie die steuerung des fotoapparats funktionieren soll.
grüße uwe
Arduino Forum > International > Deutsch (Moderator: uwefed) > Hilfe bei millis()
arduino
Comments
Post a Comment