Pages: [1]   Go Down
Author Topic: Need help!!  (Read 397 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LED program not working need help dont know why

Below is code
Code:
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);
   }
}
}
Logged

Offline Offline
God Member
*****
Karma: 19
Posts: 785
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LED program not working need help dont know why

Below is code
Code:


   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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
   for ( counter=0; counter = 5; counter++){
is doing what you think it's doing.
« Last Edit: February 28, 2013, 09:29:21 pm by Arrch » Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
for ( counter=0; counter < 5; counter++) {

Logged

Pages: [1]   Go Up
Jump to: