Go Down

Topic: Et LED prosjekt som ikke fungerer (Read 706 times) previous topic - next topic

magga97

Hei har et problem med at lys diodene mine ikke vil lyse i en sekvens jeg har laget kan noen si meg hva som er feilen?

Code: [Select]
int ledPin1 = 2;
int ledPin2 = 4;
int ledPin3 = 7;
int ledPin4 = 8;
int ledPin5 = 12;
int ledPin6 = 13;

void setup(){
  Serial.begin(9600);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
}

void loop(){
  int k;
  int p1;
  int p2;
  int p3;
  int p4;
  int p5;
  int p6;
  int x;
  int y;
  int z;
  int pt1;
  int pt2;
  int pt3;
  int pt4;
  int pt5;
  int pt6;
 
  x = 600;
  y = 10;
  z = 1202;
  k = true;
  if (k = true){
    if (p1 < x){
      p1 = p1 + y;
      delay(pt1);
    }
    else if (p1 > y || p2 < x){
      p2 = p2 + y;
      delay(pt2);
    }
    else if (p2 > y || p3 < x){
      p3 = p3 + y;
      delay(pt3);
    }
    else if (p3 > y || p4 < x){
      p4 = p4 + y;
      delay(pt4);
    }
    else if (p4 > y || p5 < x){
      p5 = p5 + y;
      delay(pt5);
    }
    else if (p5 > y || p6 < x){
      p6 = p6 + y;
      delay(pt6);
    }
    else if (p1 == x && p2 == x && p3 == x && p4 == x && p5 == x && p6 == x){
      p1 = 0;
      p2 = 0;
      p3 = 0;
      p4 = 0;
      p5 = 0;
      p6 = 0;
    }
    else if (pt1 <= z){
      pt1 = p1 + 1 * 2;
    }
    else if (pt2 <= z){
      pt1 = p2 + 1 * 2;
    }
    else if (pt3 <= z){
      pt1 = p3 + 1 * 2;
    }
    else if (pt4 <= z){
      pt1 = p4 + 1 * 2;
    }
    else if (pt5 <= z){
      pt1 = p5 + 1 * 2;
    }
    else if (pt6 <= z){
      pt1 = p6 + 1 * 2;
    }
   
  }
  else if (k = true){
    digitalWrite(ledPin1, HIGH);   
    delay(p1);                 
    digitalWrite(ledPin1, LOW);   
    delay(p1);
  }
  else if (k = true){
    digitalWrite(ledPin2, HIGH);   
    delay(p2);                 
    digitalWrite(ledPin2, LOW);   
    delay(p2);
  }
  else if (k = true){
    digitalWrite(ledPin3, HIGH);   
    delay(p3);                 
    digitalWrite(ledPin3, LOW);   
    delay(p3);
  }
  else if (k = true){
    digitalWrite(ledPin4, HIGH);   
    delay(p4);                 
    digitalWrite(ledPin4, LOW);   
    delay(p4);
  }
  else if (k = true){
    digitalWrite(ledPin5, HIGH);   
    delay(p5);                 
    digitalWrite(ledPin5, LOW);   
    delay(p5);
  }
  else if (k = true){
    digitalWrite(ledPin6, HIGH);   
    delay(p6);                 
    digitalWrite(ledPin6, LOW);   
    delay(p6);
  }
}

Hipsu

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;

int p1;
int x;
int y;
int k;

void setup() {
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);

  x = 300;
  y = 10;
  k = 1;
}

void loop()
{

  if (k == 1)
  {
    p1 = p1 + y;
  }

  if (p1 >= x)
  {
    k = 0;
  }

  if (k == 0)
  {

    p1 = p1 - y ;
  }

  if (p1 <= 1)
  {
    k = 1;
  }
 
  digitalWrite(led1, HIGH);
  delay(p1);
  digitalWrite(led1, LOW);
  delay(p1);

  digitalWrite(led2, HIGH);
  delay(p1);
  digitalWrite(led2, LOW);
  delay(p1);

  digitalWrite(led3, HIGH);
  delay(p1);
  digitalWrite(led3, LOW);
  delay(p1);

  digitalWrite(led4, HIGH);
  delay(p1);
  digitalWrite(led4, LOW);
  delay(p1);

  digitalWrite(led5, HIGH);
  delay(p1);
  digitalWrite(led5, LOW);
  delay(p1);

  digitalWrite(led6, HIGH);
  delay(p1);
  digitalWrite(led6, LOW);
  delay(p1);
}
Ei se toimi ellei sitä ohjelmoi toimivaksi.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy