lastchancename:
OP,
I'll go out on a limb, and you may hate me for this - but you have missed the basic language tutorials entirely.
Go back to the Forum Home Page, and study HOW to use the Arduino language (C/C++) - and it's specifics to the Arduino platform.To read a pin's state - as noted above, you use digitalRead()
To set a pin's state - as noted above, you use digitalWrite()To loop - ignore the loop() function - that't the main 'container' function of Arduino-land.
It does loop - but outside the scope of anything you are likely to be doing at this stage.Looping within your functions may achieved be with for(), do-while() or other constructs.
While you're learning, see if you can abandon delay() once you have the basics working.
Is this a better code then not using the loop within functions?
const int LED1 = 2;
const int LED2 = 4;
const int KNOP = 7;
unsigned long previousMillis = 0;
long OnTime = 500;
long OffTime = 750;
int ledState = LOW;
int Status ;
void setup () {
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (KNOP, INPUT);
}
void loop(){
Status = digitalRead(KNOP);
if(Status == HIGH){
LEDaan ();
LEDuit2();
}
else {
LEDuit ();
LEDaan2 ();
}
}
void LEDaan() {
var2 = 0;
while(var2 < 400){
var2++;
digitalRead(LED2)
unsigned long currentMillis = millis();
if((LED2 == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW;
previousMillis = currentMillis;
digitalWrite(LED2, LOW);
}
else if ((LED2 == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH;
previousMillis = currentMillis;
digitalWrite(LED2, HIGH);
}
}
}
void LEDuit(){
digitalWrite(LED2, LOW);
}
void LEDaan2(){
var = 0;
while(var < 200){
var++;
digitalRead(LED1)
unsigned long currentMillis = millis();
if ((LED1 == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW;
previousMillis = currentMillis;
digitalWrite(LED1, LOW);
}
else if ((LED1 == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH;
previousMillis = currentMillis;
digitalWrite(LED1, HIGH);
}
}
}
void LEDuit2(){
digitalWrite (LED1, LOW);
}