One more knight rider project - My first

Hallo and from me

recently i discovered the arduino world

i have ordered an arduino mega

i want to make two led bars like those on the mustung

i will use 2x46 leds

46 pins for the anodes
and 2 pins for all the kathodes on each bar (with transistors)

so i wiil be able to controll 92 leds


exept the nornal scan and the knight rider two thousand scan i want to use it as a vu meter

i will conect a mic on one analog input and read the value

the i map the analog read (0-1023) to the numbers of leds (0-91)

so if the number on leds (k) is below the middle i will turn on the first led bar and the number of the led that i want

if it is more than the half leds i will have to light all the half turn them off and light the other

but my questions is how can i write

do “something” for this ammount of time?

thanks

void k_leds_from_left_to_right (int k, int speedtime) // k(0,91)
{

if (k<= 45)
{

digitalWrite (leda,HIGH);

for (i=0; i=k; i++) // ligh the leds
{
digitalWrite (led*,HIGH);*

  • }*

  • delay (speedtime); // wait with the leds on*

  • all_low();*

  • }*

  • if (k>45)*

  • { *

  • for (i=0; i=speedtime; i++)*

  • {*

  • digitalWrite (leda,HIGH);*

  • for (j=0; j=45; j++)*

  • {*

  • digitalWrite (led[j],HIGH);*

  • }*

  • all_low();*

  • digitalWrite (ledb,HIGH);*

  • for (j=46; j=(46+k); j++)*

  • {*

  • digitalWrite (led[j],HIGH);*

  • }*

  • all_low();*

  • }*

  • }*

} // k_leds_from_left_to_right close
[/quote]
*all_low(); : makes all the ouputs low

i found the way

void k_leds_from_left_to_right (int k, int speedtime) // k(0,91)
{
  
  
  if (k<= 45)
  {
    
    digitalWrite (leda,HIGH);
    
    for (i=0; i=k; i++) // ligh the leds
    {
      digitalWrite (led[i],HIGH);
    }
    
    delay (speedtime); // wait with the leds on
    
    all_low();
    
  }
  
  
  timecounter = millis();
  timerunning = 0;
  
  if (k>45)
  {    
    for (i=1; ((timerunning-timecounter)<speedtime); i++ )
    {
      
      digitalWrite (leda,HIGH);
      for (j=0; j=45; j++)
      {
        digitalWrite (led[j],HIGH);
      }
      all_low();
      
      digitalWrite (ledb,HIGH);
      for (j=46; j=(46+k); j++)
      {
        digitalWrite (led[j],HIGH);
      }
      all_low();
      
      timerunning = millis();
    }
  }
  
  
} // k_leds_from_left_to_right close

i got my arduino mega yesterday

and i have faced up some problems

first of all

my void loop section

void loop()
{
   
  
  //********** Info display **********
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    Made By:    ");
  moveCursor("02", "01");
  displayMessage("    herctrap    ");
  delay (1500);


  //get time from the sensor
  time = map(analogRead(speedo), 0, 1023, 20, 1000); 
  
  
  // somewhere here i wiil read my digital and analog inputs and i will call some functgions


} // void loop close

but if i change it a litle bit to that

void loop()
{
   
  
  //********** Info display **********
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    Made By:    ");
  moveCursor("02", "01");
  displayMessage("    herctrap    ");
  delay (1500);


  //get time from the sensor
  time = map(analogRead(speedo), 0, 1023, 20, 1000); 
  
   clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    test    ");
  


} // void loop close

then it loops and displays only the first message on the screen

i can see it to flick on the screen every 1.5 sec

i cant tell you if it reads the time from the sensor

also if i write

kitt2008scan (time); bellow to the //get time from the sensor time = map(analogRead(speedo), 0, 1023, 20, 1000);

still nothing happens it loops through the first meessage

also i have this below the void loop close

void kitt2008scan (int speedtime)
{
  
      int i;
      int j;
  
      digitalWrite (leda,HIGH); // both led bars work the same
      digitalWrite (ledb,HIGH);
      
      
      loop();
      { 
      
        
      for (i=0; i=45; i++) // going from the side to the middle by turning on the leds
      {
       digitalWrite (led[i],HIGH);         
       delay (speedtime);    
      }
      
      for (i=0; i=45; i++) // going from the side to the middle by turning off the leds
      {
       digitalWrite (led[i],LOW);
       delay (speedtime);
      } 
       
       for (i=45; i=0; i--) // going from the middle to the side by turning on the leds
      {
       digitalWrite (led[j],HIGH);         
       delay (speedtime);    
      }
      
      for (i=0; i=45; i++)// going from the middle to the side by turning off the leds
      {
       digitalWrite (led[j],LOW);
      } 
      
      
      }
  
  
  
} // void kitt2008scan close

i removed the analogRead and it move on

void loop()
{
   
  
  //********** Info display **********
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    Made By:    ");
  moveCursor("02", "01");
  displayMessage("    herctrap    ");
  delay (1500);


  
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    MdsfBy:    ");
  moveCursor("02", "01");
  displayMessage("    hcxcfzcra");
  delay (1500);
  
  
  time = 0;
  
  kitt2008scan (time);

  
  


} // void loop close





// ------------------------------------------------------------------------------------------------------------------ scan patterns ------------------------------------------------------------------------------------------------------------------

/*

Remind:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

void kitt2008scan (int speedtime)
void knight_rider_two_thousand (int speedtime)

void four_groups_blink_twice (int speedtime)

void bar_blink_twice (int speedtime)
void bars_blink_twice (int speedtime)

void all_high()
void all_low()

void k_leds_from_left_to_right (int k, int speedtime) // k(0,91)
void k_leds_from_middle_to_sides (int k, int speedtime) // k(45,0)
void k_leds_from_sides_to_middle (int k, int speedtime) // k(0,45)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

*/


void kitt2008scan (int speedtime)
{
    clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage(" 323 ");
  moveCursor("02", "01");
  displayMessage(" 2121");
  delay (1500);
      int i;
      int j;
  
      digitalWrite (leda,HIGH); // both led bars work the same
      digitalWrite (ledb,HIGH);
      
      
      loop();
      { 
      
     c
  
} // void kitt2008scan close

but now it loops through the 3 messages

shouldn't it to show each message one time

and then loops through

the

void loop()
{
   
  
  //********** Info display **********
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    Made By:    ");
  moveCursor("02", "01");
  displayMessage("    herctrap    ");
  delay (1500);


  
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    MdsfBy:    ");
  moveCursor("02", "01");
  displayMessage("    hcxcfzcra");
  delay (1500);
  
  
  time = 0;
  
  kitt2008scan (time);

  
  


} // void loop close





// ------------------------------------------------------------------------------------------------------------------ scan patterns ------------------------------------------------------------------------------------------------------------------

/*

Remind:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

void kitt2008scan (int speedtime)
void knight_rider_two_thousand (int speedtime)

void four_groups_blink_twice (int speedtime)

void bar_blink_twice (int speedtime)
void bars_blink_twice (int speedtime)

void all_high()
void all_low()

void k_leds_from_left_to_right (int k, int speedtime) // k(0,91)
void k_leds_from_middle_to_sides (int k, int speedtime) // k(45,0)
void k_leds_from_sides_to_middle (int k, int speedtime) // k(0,45)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

*/


void kitt2008scan (int speedtime)
{
    clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage(" 323 ");
  moveCursor("02", "01");
  displayMessage(" 2121");
  delay (1500);
      int i;
      int j;
  
      digitalWrite (leda,HIGH); // both led bars work the same
      digitalWrite (ledb,HIGH);
      
      
      loop();
      { 
      
        
      for (i=0; i=45; i++) // going from the side to the middle by turning on the leds
      {
       digitalWrite (led[i],HIGH);         
       delay (speedtime);    
      }
      
      for (i=0; i=45; i++) // going from the side to the middle by turning off the leds
      {
       digitalWrite (led[i],LOW);
       delay (speedtime);
      } 
       
       for (i=45; i=0; i--) // going from the middle to the side by turning on the leds
      {
       digitalWrite (led[j],HIGH);         
       delay (speedtime);    
      }
      
      for (i=0; i=45; i++)// going from the middle to the side by turning off the leds
      {
       digitalWrite (led[j],LOW);
      } 
      
      
      }
  
  
  
} // void kitt2008scan close
void kitt2008scan (int speedtime)
{
  
  clearLCD(); // clear the lcd screen
  displayMessage("kitt2008scan");
  delay (1000);
  
      int i;
      int j;
      
        clearLCD(); // clear the lcd screen
  displayMessage("i j ");
  delay (1000);
  
      digitalWrite (leda,HIGH); // both led bars work the same
      digitalWrite (ledb,HIGH);
      
        clearLCD(); // clear the lcd screen
  displayMessage("led a b");
  delay (1000);
      
      
      loop();
      { 
          clearLCD(); // clear the lcd screen
  displayMessage("looping");
  delay (1000);
      
        
      for (i=0; i=45; i++) // going from the side to the middle by turning on the leds
      {
       digitalWrite (led[i],HIGH);         
       delay (speedtime);    
      }
      
      for (i=0; i=45; i++) // going from the side to the middle by turning off the leds
      {
       digitalWrite (led[i],LOW);
       delay (speedtime);
      } 
       
       for (i=45; i=0; i--) // going from the middle to the side by turning on the leds
      {
       digitalWrite (led[j],HIGH);         
       delay (speedtime);    
      }
      
      for (i=0; i=45; i++)// going from the middle to the side by turning off the leds
      {
       digitalWrite (led[j],LOW);
      } 
      
      
      }
  
  
  
} // void kitt2008scan close

it prints out only the kitt2008scan and i j not the looping

it goes from the begging

why ? it goes from the begging

it prints out only the kitt2008scan and i j not the looping

it goes from the begging

why ?

Because of this:

      loop();

You call loop from the middle of your function. Of course, loop is going to start over.

so loop(); means

yes

i thought that it would start loopinh what it is inside the {} bellow of loop

i get it now


is there any other function / command for infinity loop

?

There are a couple of ways to create an infinite loop.

while(1)
{
   // Loop forever
}

for(;;)
{
   // Loop forever
}

Whichever you use, you need to provide a way to break out of the loop, if you want to do something else.

thanks more problems now

//******************** Led outputs ********************
int led[ ] = {53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22,   21, 20, 19, 18, 17, 16,   2, 3, 4, 5, 6, 7, 8, 9   };
 


//******************** Bar outputs ******************** 
int leda = 12;
int ledb = 13;



//************************************************************ inputs ************************************************************
 


 //********** i/o scan modes on analog inputs **********
 int scan1 = (8+54) ;
 int scan2 = (9+54);
 int scan3 = (10+54);
 int scan4 = (11+54);
 int scan5 = (12+54);
 int scan6 = (13+54);
 int scan7 = (14+54);
 



 //******************** inputs as i/o for the scan mode ********************
int simplescan = (0+54) ; // i/o switch for simple scann
int sensorenable = (1+54) ; // i/o switch for voice scan
int lightenable= (2+54) ; // i/o switch for light scan
int motionenable = (3+54) ; // i/o switch for motion enable scan



 //******************** analog inputs for the scan modes ********************
int speedo = 4; // analog input for speed controll
int sensor1 = 5;       // analog voice input for scan
int light = 6;      // analog input for light scan
int motion = 7;       // analog input for the motion detection



 //****************************** basic values ******************************
long calibrationtime = 5000; // the time limit for the calibration

int time; // for the time delay



//******************** for help ********************
int k;

long rnda; // for random production
long rndb;

int minvalue; //for the analog calibration
int maxvalue;


// ------------------------------------------------------------------------------------------------------------------ declarations ------------------------------------------------------------------------------------------------------------------
void setup()
{

//******************** define as outputs ********************
   
        // 46 led controll  
      for (int leds = 0; leds < 45; leds++) 
      {
      pinMode(led[leds], OUTPUT);
      }
    
                
        
        // two bar led controll        
        pinMode (leda, OUTPUT);
        pinMode (ledb, OUTPUT);
       
       
       
        pinMode (simplescan, INPUT);
        pinMode (sensor1, INPUT);
        pinMode (lightenable, INPUT);
        pinMode (motionenable, INPUT);
           
         
           
        pinMode (scan1, INPUT);
        pinMode (scan2, INPUT);
        pinMode (scan3, INPUT);
        pinMode (scan4, INPUT);
        pinMode (scan5, INPUT);
        pinMode (scan6, INPUT);
        pinMode (scan7, INPUT);
        
        
        
        //start the lcd com
        Serial.begin(9600);

        
        
        
} // void setup close

i thought with the above i will be able to control the pins
53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 2, 3, 4, 5, 6, 7, 8, 9
on the mega

witch will be led[0] to led[45]

but i cant

i thought with the above i will be able to control the pins

You should be able to.

but i cant

Why not? What evidence do you have that there is a problem? What is the problem?

it makes high only the leda and ledb pins

while running on that

void kitt2008scan (int speedtime)
{
  
  
  //********** Info display **********
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("Patterns");
  moveCursor("02", "01");
  scrollMessage(02,8,"Knight rider 2008");
  delay(1000);
  
  

  
      int i;
      int j;
      
        clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("i j");
  delay (2000);
  
      digitalWrite (leda,HIGH); // both led bars work the same
      digitalWrite (ledb,HIGH);
      
        clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("led a b");
  delay (2000);
      
      
      while ( (simplescan = HIGH ) && (scan1 = HIGH) )
      { 
      
             clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("while");
  delay (2000);
        
      for (i=0; i=45; i++) // going from the side to the middle by turning on the leds
      {
        
             clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("for");
  delay (2000);
  
       digitalWrite (led[i],HIGH);         
       delay (speedtime);    
      }
      
           clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("leds");
  delay (2000);
      
      for (i=0; i=45; i++) // going from the side to the middle by turning off the leds
      {
       digitalWrite (led[i],LOW);
       delay (speedtime);
      } 
       
       for (i=45; i=0; i--) // going from the middle to the side by turning on the leds
      {
       digitalWrite (led[j],HIGH);         
       delay (speedtime);    
      }
      
      for (i=0; i=45; i++)// going from the middle to the side by turning off the leds
      {
       digitalWrite (led[j],LOW);
      } 
      
       
      
      }
  
  
  
} // void kitt2008scan close

the last msg that i see on screen is "for"

and then stays there

for (i=0; i=45; i++)

The middle clause in a for statement is a while clause. The body of the loop is executed while (and only when) the middle clause is true.

You want the middle clause to be i<=45;

yes i was thinking with the basic for


stillnot works

void loop()
{
  
  digitalWrite (led[45],HIGH);
  delay(5000);


  //********** Info display **********
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    Made By:    ");
  moveCursor("02", "01");
  displayMessage("    herctrap    ");
  delay (2000);

  
  time = map(analogRead(speedo), 0, 1023, 20, 1000); 
 
time = 1000;
 
 if (simplescan = HIGH )
 {
   if (scan1 = HIGH) kitt2008scan (time);
   if (scan2 = HIGH) knight_rider_two_thousand (time);
   if (scan3 = HIGH) four_groups_blink_twice (time);
   if (scan4 = HIGH) bar_blink_twice (time);
   if (scan5 = HIGH) bars_blink_twice (time);
   if (scan6 = HIGH) all_high ();
   if (scan7 = HIGH) kitt2008scan (time);
   
      
   
   
 }
 
 
  if (sensorenable = HIGH )
 {
   
   
 }
 
 
  if (lightenable = HIGH )
 {
   
   
 }
 
 
  if (motionenable = HIGH )
 {
   
   
 }


 


  
  
 

} // void loop close

digitalWrite (led[45],HIGH);

i put a led on pin 9 on the mega
but it never lights up

//******************** Led outputs ********************
int led[ ] = {53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22,   21, 20, 19, 18, 17, 16,   2, 3, 4, 5, 6, 7, 8, 9   };
 


//******************** Bar outputs ******************** 
int leda = 12;
int ledb = 13;



//************************************************************ inputs ************************************************************
 


 //********** i/o scan modes on analog inputs **********
 int scan1 = (8+54) ;
 int scan2 = (9+54);
 int scan3 = (10+54);
 int scan4 = (11+54);
 int scan5 = (12+54);
 int scan6 = (13+54);
 int scan7 = (14+54);
 



 //******************** inputs as i/o for the scan mode ********************
int simplescan = (0+54) ; // i/o switch for simple scann
int sensorenable = (1+54) ; // i/o switch for voice scan
int lightenable= (2+54) ; // i/o switch for light scan
int motionenable = (3+54) ; // i/o switch for motion enable scan



 //******************** analog inputs for the scan modes ********************
int speedo = 4; // analog input for speed controll
int sensor1 = 5;       // analog voice input for scan
int light = 6;      // analog input for light scan
int motion = 7;       // analog input for the motion detection



 //****************************** basic values ******************************
long calibrationtime = 5000; // the time limit for the calibration

int time; // for the time delay



//******************** for help ********************
int k;

long rnda; // for random production
long rndb;

int minvalue; //for the analog calibration
int maxvalue;


// ------------------------------------------------------------------------------------------------------------------ declarations ------------------------------------------------------------------------------------------------------------------
void setup()
{

//******************** define as outputs ********************
   
        // 46 led controll  
      for (int leds = 0; leds < 45; leds++) 
      {
      pinMode(led[leds], OUTPUT);
      }
    
                
        
        // two bar led controll        
        pinMode (leda, OUTPUT);
        pinMode (ledb, OUTPUT);
       
       
       
        pinMode (simplescan, INPUT);
        pinMode (sensor1, INPUT);
        pinMode (lightenable, INPUT);
        pinMode (motionenable, INPUT);
           
         
           
        pinMode (scan1, INPUT);
        pinMode (scan2, INPUT);
        pinMode (scan3, INPUT);
        pinMode (scan4, INPUT);
        pinMode (scan5, INPUT);
        pinMode (scan6, INPUT);
        pinMode (scan7, INPUT);
        
        
        
        //start the lcd com
        Serial.begin(9600);

        
        
        
} // void setup close


// ------------------------------------------------------------------------------------------------------------------ programm running ------------------------------------------------------------------------------------------------------------------
void loop()
{
  
 
  
  //********** Info display **********
  clearLCD(); // clear the lcd screen
  moveCursor("01", "01");
  displayMessage("    Made By:    ");
  moveCursor("02", "01");
  displayMessage("    herctrap    ");
  delay (2000);

  
  time = map(analogRead(speedo), 0, 1023, 20, 1000); 
 
 
 if (simplescan = HIGH )
 {
   if (scan1 = HIGH) kitt2008scan (time);
   if (scan2 = HIGH) knight_rider_two_thousand (time);
   if (scan3 = HIGH) four_groups_blink_twice (time);
   if (scan4 = HIGH) bar_blink_twice (time);
   if (scan5 = HIGH) bars_blink_twice (time);
   if (scan6 = HIGH) all_high ();
   if (scan7 = HIGH) kitt2008scan (time);
   
      
   
   
 }
 
 
  if (sensorenable = HIGH )
 {
   
   
 }
 
 
  if (lightenable = HIGH )
 {
   
   
 }
 
 
  if (motionenable = HIGH )
 {
   
   
 }



  
  
 

} // void loop close

also i have left the pins

analoginput 0,1,2,3,8,9,10,11,12,13,14

unconnected and the arduino takes them as HIGH

i also connect them to the ground and also takes them as HIGH

if (simplescan = HIGH )

= is an assignment operator. == is the equality operator.

To compare simplescan to HIGH, use the == operator.

if (simplescan [glow]==[/glow] HIGH )
 if (simplescan == HIGH )
 {
   if (scan1 == HIGH) kitt2008scan (time);
   if (scan2 == HIGH) knight_rider_two_thousand (time);
   if (scan3 == HIGH) four_groups_blink_twice (time);
   if (scan4 == HIGH) bar_blink_twice (time);
   if (scan5 == HIGH) bars_blink_twice (time);
   if (scan6 == HIGH) all_high ();
   if (scan7 == HIGH) kitt2008scan (time);

but it never goes into the if i have conect the analog 0 and analog 8 with the 5v

 //********** i/o scan modes on analog inputs **********
 int scan1 = (8+54) ;
 int scan2 = (9+54);
 int scan3 = (10+54);
 int scan4 = (11+54);
 int scan5 = (12+54);
 int scan6 = (13+54);
 int scan7 = (14+54);




 //******************** inputs as i/o for the scan mode ********************
int simplescan = (0+54) ; // i/o switch for simple scann
int sensorenable = (1+54) ; // i/o switch for voice scan
int lightenable= (2+54) ; // i/o switch for light scan
int motionenable = (3+54) ; // i/o switch for motion enable scan

does this working to the arduino mega

the 54+pin

i found one more mistake

if (digitalRead(scan2)== HIGH ) digitalWrite (ledPin,HIGH);

if the digitalread of the button in HIGH

http://www.youtube.com/watch?v=PGVv9TrGBeo

This was my first test with arduino and my project

i dont have all the equipment yet

i am still waititng the leds and the transistors

the project will totaly have 92 channels

46 in each bar

it would be able to work as an vu meter also

a temperature meter

i light meter

a motion detector


i found some t10 led in the garage and i couldnt wait the led to test it

this was the leds from channel 8 to channel 22

so the paterns are not show corectly

the speed is controlled by a rotary switch but i dont have it yet

the patterns are also controlled by a rotary switch

the usb cable was only for power not data

http://www.youtube.com/watch?v=d3RwY2-AjxE

vu meter with a pc microphone

http://www.youtube.com/watch?v=p4KCEE3yFWg

and

http://www.youtube.com/watch?v=3mdG6pUF-1o