Pages: [1]   Go Down
Author Topic: please help with this code...  (Read 246 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int cycleTime = 1300;
int pins[] = {  3, 4, 5, 6, 7, 8, 9, 10, 11 };
int numPins = 9;
int numCycles = 46;
int cycle = 0;
int pinDigital[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int pinStatus[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int pinIntensity[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int intensityCurve[] = {101, 95, 85, 75, 50,0};
int intensityMark = 100;
int timer = 0;
int cycleDefs[46][9] =
  {
//    {5,0,5,0,5,0,5,0,5},
//    {0,0,5,5,5,5,0,0,0},
    {1,0,0,0,0,0,0,0,0},
    {1,1,0,0,0,0,0,0,0},
    {1,1,1,1,0,0,0,0,0},
    {2,1,1,1,1,1,0,0,0},
    {3,2,2,2,1,1,1,1,1},
    {5,4,4,3,2,1,1,1,1},
    {5,5,4,4,3,2,1,1,1},
    {5,5,5,4,4,3,2,1,1},
    {5,5,5,5,5,4,3,2,1},
    {5,5,5,5,5,5,4,3,2},
    {5,5,5,5,5,5,5,4,3},
    {5,5,5,5,5,5,5,5,5},
    {4,5,5,5,5,5,5,5,5},
    {3,3,5,5,5,5,5,5,5},
    {2,3,4,5,5,5,5,5,5},
    {1,2,2,4,5,5,5,5,5},
    {0,0,1,2,4,5,5,5,5},
    {0,0,0,1,2,4,5,5,5},
    {0,0,0,1,1,1,3,5,5},
    {0,0,0,0,1,1,3,3,5},
    {0,0,0,0,0,0,1,3,5},
    {0,0,0,0,0,0,0,1,5},
    {0,0,0,0,0,0,0,0,3},
//    {5,0,5,0,5,0,5,0,5},
 
    {0,0,0,0,0,0,0,0,3},
    {0,0,0,0,0,0,0,1,5},
    {0,0,0,0,0,0,1,3,5},
    {0,0,0,0,1,1,3,3,5},
    {0,0,0,1,1,1,3,5,5},
    {0,0,0,1,2,4,5,5,5},
    {0,0,1,2,4,5,5,5,5},
    {1,2,2,4,5,5,5,5,5},
    {2,3,4,5,5,5,5,5,5},
    {3,3,5,5,5,5,5,5,5},
    {4,5,5,5,5,5,5,5,5},
    {5,5,5,5,5,5,5,5,5},
    {5,5,5,5,5,5,5,4,3},
    {5,5,5,5,5,5,5,3,2},
    {5,5,5,5,5,5,4,3,2},
    {5,5,5,5,5,4,3,2,1},
    {5,5,4,4,3,2,1,1,1},
    {5,4,4,3,2,1,1,1,1},
    {3,2,2,2,1,1,1,1,1},
    {2,1,1,1,1,1,0,0,0},
    {1,1,1,1,0,0,0,0,0},
    {1,1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0,0}
 
    };


 
void setup()
{
  int i;
//  Serial.begin(9600);
//  Serial.println("Program Loaded"); 
  for (i = 0; i < numPins; i++)
  {   
    pinMode(pins[i], OUTPUT);   
  }
  pinMode(13,OUTPUT);
}


void loop()
{
 
  int i;
  int tmp;

 
  timer++;
  if((timer % intensityMark)==0)
  {
    for(i = 0; i<numPins; i++)
    {
      int targetIntensity = intensityCurve[pinStatus[i]];
      if(targetIntensity > pinIntensity[i])
      {
        pinIntensity[i]++;
      }
      else if(targetIntensity < pinIntensity[i]) 
      {
        pinIntensity[i]--;
      }
    }
  }

  for (i = 0; i < numPins; i++)
  {
    if((timer % intensityMark) >= pinIntensity[i])
    {
      if(pinDigital[i] == 0)
      {
         pinDigital[i] = 1;
         digitalWrite(pins[i],HIGH);
      }
     
    }
    else
    {
      if(pinDigital[i] == 1)
      {
         pinDigital[i] = 0;
         digitalWrite(pins[i],LOW);
      }
    }
  }
  if(timer == cycleTime)
  {
    timer = 0;
    cycle++;
  }
  else
  {
    return;
  }
//  Serial.read();
  if(cycle >= (numCycles))
  {
    cycle = 0;
    digitalWrite(13,HIGH);
  }
  if(cycle == 20)
  {
    digitalWrite(13,LOW);   
  }

  for(i=0; i<numPins; i++)
  {
    pinStatus[i] = cycleDefs[cycle][i]; 
  }

}





can someone please tell me how this code works.if i want to change the effects how do i do it..which lines do i need to change.how do i change the speed..
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12428
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how do i change the speed..
Serial.begin(115200);  ???

Is it too slow => faster processor
too fast =>  add delay(some value);  at the place you want a delay..

Quote
can someone please tell me how this code works
Take paper and pencil and follow the code line by line. write a list of all variables declared and put their value after it, chnage them according to the algorithm and you will understand.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: