Go Down

Topic: Need help!! (Read 420 times) previous topic - next topic

TheSpook

LED program not working need help dont know why

Below is code
Code: [Select]
void setup (){
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  Serial.begin(9600);
 
}

void loop(){
  int Portresult;
  int val;
  int bitval;
  int counter = 0;
   for ( counter=0; counter = 5; counter++){
     
     bitRead(Portresult,counter);
     
      val=bit(counter);
      counter = counter + 2;
      if(val=='1') { digitalWrite(counter,HIGH) ; }
      else if (val=='0') {digitalWrite(counter,LOW);
   }
}
}

Delta_G


LED program not working need help dont know why

Below is code
Code: [Select]



  for ( counter=0; counter = 5; counter++){
     
 



Well, I have no idea what the code is supposed to do.  You should probably tell what you want it to do.  I don't have a crystal ball and I can't read minds.

I have no idea what actually happens.  You should probably tell that too.  I mean if you really want help.

But I do know that this for loop will never execute.  On the very first iteration counter is 0 and the condition to run the loop says it has to equal 5.  0 != 5 so the loop will never run.

TheSpook

ok well im creating a program on vb that controls leds the vb program generates a 5bit binary number which i have then ported to arduino. i then want arduino to read each bit separately and then check if its a 1 or 0

Arrch

#3
Mar 01, 2013, 03:27 am Last Edit: Mar 01, 2013, 03:29 am by Arrch Reason: 1
You must have missed the thread titled Read this before posting a programming question.

But, to get you started, you should look at a few examples of for loop to see how they work, because I sincerely doubt this piece
Code: [Select]

   for ( counter=0; counter = 5; counter++){

is doing what you think it's doing.

spatula

Start by correcting this typo, it would make some progress. Then repost the code and tell us what you expect from it and what you got.

Code: [Select]

for ( counter=0; counter < 5; counter++) {



Go Up