Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: Loop over Array values. on: July 31, 2013, 09:32:21 am
thanks couldn't see the wood for the tree's smiley-eek
2  Using Arduino / Programming Questions / Re: Loop over Array values. on: July 31, 2013, 08:39:18 am

Thanks Guys

Now its failing in the second "switch" section on case 5 onwards .case 6 is fine?

Code:
void setup()
{

  /* add setup code here */

}

void loop()
{

  //**Hard Coded Value for BPM

            double n = 60;

            //**Hard Coded Value for aaray size

            int Ar1 = 8;

            //**Hard Coded Value

            int n1 = 4; // This will be a user entered value eventually but for now its hard coded.

            double mili = 1000;

            switch (n1)
            {
                case 1:
                 
                    mili = (n / 60) * 1000;

                    break;

                case 2:
                   
                    mili = (n / 120) * 1000;

                    break;

                case 3:
             
                    mili = (n / 240) * 1000;

                    break;

                case 4:
                 
                    mili = (n / 480) * 1000;

                    break;

                default:
                 
                    break;
            }

            //**Hard Coded Value number of times to repeat

            int Rp1 = 1;

            //**Hard Coded Value


int arr [] = { 1, 2, 3, 4, 5, 6, 5, 4 };



            // Loop over LED's

            for (int i = 0; i < Rp1; i++)
           
{

                /*foreach (int s in arr)*/

for (int i=0; i<sizeof arr/sizeof arr[0]; i++)

{
int s = arr[i];
             
{

                    switch (s)
                   
                        case 6:

                            //Console.WriteLine("Light the sixth LED");
                            break;

                        case 5:                                                                     /*<<<<<<<<<<<Fails Here*/

                           // Console.WriteLine("Light the Fifth LED");
                            break;

                        case 4:                                                                    /* <<<<<<<<<<<Fails Here*/

                           // Console.WriteLine("Light the Fouth LED");
                            break;

                        case 3:                                                                    /*<<<<<<<<<<<Fails Here*/

                           // Console.WriteLine("Light the Third LED");
                            break;

                        case 2:                                                                   /* <<<<<<<<<<<Fails Here*/

                           // Console.WriteLine("Light the Second LED");
                            break;

                        case 1:                                                                   /* <<<<<<<<<<<Fails Here*/

                           // Console.WriteLine("Light the First LED");
                            break;

                        case 0:

                           // Console.WriteLine("Pause ,do nothing");
                            break;
                    }
}

               

                }
}

Regards

Geoff
3  Using Arduino / Programming Questions / Loop over Array values. on: July 31, 2013, 07:57:22 am

hello I'm converting a C# piece of code and am stumped over this line

Code:
 
int arr [] = { 1, 2, 3, 4, 5, 6, 5, 4 };



            // Loop over LED's

            for (int i = 0; i < Rp1; i++)
           
{

                [b]foreach (int s in arr)[/b]   <<<<<<<Does not like this line
             
{

                    switch (s)
                   
                        case 6:

                            //Console.WriteLine("Light the sixth LED");
                            break;

                        case 5:

                           // Console.WriteLine("Light the Fifth LED");
                            break;

                        case 4:

                           // Console.WriteLine("Light the Fouth LED");
                            break;

                        case 3:

                           // Console.WriteLine("Light the Third LED");
                            break;

                        case 2:

                           // Console.WriteLine("Light the Second LED");
                            break;

                        case 1:

                           // Console.WriteLine("Light the First LED");
                            break;

                        case 0:

                           // Console.WriteLine("Pause ,do nothing");
                            break;
                    }
}

               

                }code]

What would be the c++ equivalent?

Thanks

Geoff
4  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 24, 2013, 10:37:47 am
Cheers Rob  smiley

I'll give that a go over the weekend

I did write this up in c# today hoping it would give you the heads up as what I'm trying to do but you beat me to it.

Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace AarayTest1

{

    class Program

    {

        static void Main(SEQ[] args)

        {


            string[] arr = new SEQ[7]; // Initialize

            arr[0] = "6";               // Element 1

            arr[1] = "5";               // Element 2

            arr[2] = "4";             // Element 3

            arr[3] = "3";              // Element 4

            arr[4] = "2";             // Element 5

            arr[5] = "1";              // Element 6

            arr[6] = "0";              // Element 7

 

            // Loop over SEQ

            foreach (SEQ s in arr)

         

            {

 

                switch (s)

                {

                    case "0":

 

                        Console.WriteLine("Hit the sixth LED");

                        break;

 

                    case "1":

 

                        Console.WriteLine("Hit the Fifth LED");

                        break;

 

                    case "2":

 

                        Console.WriteLine("Hit the Fouth LED");

                        break;

 

                    case "3":

 

                        Console.WriteLine("Hit the Third LED");

                        break;

 

                    case "4":

 

                        Console.WriteLine("Hit the Second LED");

                        break;

 

                    case "5":

 

                        Console.WriteLine("Hit the First LED");

                        break;

 

                    case "6":

 

                        Console.WriteLine("Pause ,do nothing");

                        break;

                }


                Console.ReadLine(); //Pause

         
            } 

        }
        }

    }



Thanks again

Geoff
5  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 24, 2013, 02:19:56 am
Thanks guys

Braking it down to its simplest form I would say this.

LED Pattern =

0001
0010
0100
1000

Sequence pattern =

1,3,4,2

So when I read the first sequence pattern value "1" that means do LED pattern 0001. Next sequence pattern ="3" now do LED pattern 0100 etc etc.

So in essence I could change the order of when the LED's flash by using the second sequence pattern.

Regards

Geoff

6  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 23, 2013, 04:22:18 pm
Thanks Rob that's something to think about. We are 50% there  smiley

This is the first array with the sequence of lights required

Code:

//      RBGW
   B00001000,  // This is the sequence of lights required
   B00000100,
   B00001000,
   B00000001,
   B00000100,
   B00000010,
   B00001000,
   B00000001, 
   B00000010,
   B00000100,
   B00000010, 
   B00000100,
   B00001000
};

Notice I have taken out the 3 pauses as this will controlled by a second aaray to control what happens on every beat.

An array like this would fire each line of the first array.

(1,1,1,1,1,1,1,1,1,1,1,1,1)

ie, if its a "1" then execute the first line of the first aaray, when we get the next "1" execute the second line etc etc
However if we get a "0" then do nothing, then if we get a "1" execute the third line of the first aaray.

So an aaray like this (1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0) would make the lights flash in the same sequence but
we would have a pause between them. An array like this (1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1) would light the first half of
the first aaray straight away then we have a pause for 6 beats, then we complete the sequence.

So essentially we have two arrays the second of which controls when we read the first.

You ready to give up yet  smiley

Thanks

Geoff

7  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 23, 2013, 02:08:52 am
Sorry Rob I'm not making myself clear. I'm only a newb at this stuff although I've done many
of the examples on this site so not that newb.

I'll put it another way.

Lets say I have 4 coloured LEDs  Red, Blue, Green and White.

I choose the lighting sequence of, Red, Blue, Red, White, Blue, Green, Red.

Then I have a timing sequence to control when each light will come on.
So with a timing sequence of 1,1,1,1,1,1 each light will come on in the specified sequence.
At 120 bpm that's 1 light every half a second.

However if I change the timing sequence to 1,1,1,0,0,0,1,1,1 the first three will come on in sequence at 0.5 sec intervals.
Then we have a pause for three beats 1.5 sec, then the remaining lights will come on in sequence.

So when the circuit is completed I can change the Lighting and Timing sequence to what ever I choose.

Is that a better description?

Thanks

Geoff

8  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 21, 2013, 12:55:56 pm
 smiley

Thanks for AND gate idea.

One problem I will have is I have two data streams.

Timer Stream  - 1,1,1,1,1,0
Light Stream - 1,2,4,16,32,64

So with the above data i light the 1st ,2nd, 3rd ,4th ,5th LED then the 64 doesn't light.

Thanks

Geoff
9  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 20, 2013, 04:41:52 pm
Thats good to know as its not a requirement I just assumed I needed a timer. If I can do it all in the code that would be great.

As a basic example of how I see it working is as follows.

I have timer pulsing 120 BPM so counting that out would be, 1 AND 2 AND 3 AND 4 AND 5 AND 6 AND 7 AND 8 etc etc.
Lets say we have a tune, twinkle twinkle little star (Main beat are in CAPS)

TWIN-kle-TWIN-kle-LITT-le-STAR.

So the timer sequence would be

1-1-1-1-1-1-1-0

The 1's would cause the LED's to flash and the 0's would not flash. After I have that situation sorted then I can use the second Light sequence
to determine which LED light's

Does that make sense  smiley-confuse

thanks

Geoff
10  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 20, 2013, 01:35:49 pm
I think to simplify things further I will hard code the light sequence and timer sequence. After I have proved the concept
i will try to read the sequences via a file on the PC.

After I have set the BPM via the 555 timer, if that possible? its a simple matter of feeding that into the clock on the register right?

Regards

Geoff
11  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 20, 2013, 08:43:25 am
Ref - Also where is this "text file" residing, do you have an SD card or getting the data from a PC?

The files will reside on a PC.

Ref - True, but he hasn't mentioned 12v or LED strings or that he's pin bound. Is that the case JimiH?

First of all I will user basic low power LED's  connected to a breadboard to prove the concept ,after that I'm toying with the idea of using
other devices instead of the LED's, Motors, Solenoids etc etc. But to keep it as simple as possible I plan
to use LED's first of all.

Geoff
12  Using Arduino / Project Guidance / Re: shift registers ,LED's ,timer on: May 20, 2013, 08:32:54 am
Ref - First thing, why do you need a shift register

I'm basically starting out using the "Shift Out" tutorial which uses shift registers and LED's. That's 50% of my project I think.

I want to modify it so I can specify the lighting sequence and the timing of the lighting events using text files.

Thanks for the info about TPIC6B595's that will be useful.

Regards

Geoff

13  Using Arduino / Project Guidance / shift registers ,LED's ,timer on: May 20, 2013, 06:24:06 am
Arduino Project

Hello, I have in my mind a project like below.

1   Connect the arduino with 6 LED's controlled with a Shift register

2   Read from a text file the light sequence and put into the register (1,2,4,8,16,32,16,8,4,2)
   So this would light each LED in sequence like the KITT sweep example.

3   Connect a timer to the project which would control when to perform the next LED lighting event from reading another text file, example 1,0,1,0,1,0

4   So if the clock was set to 60 BPM, the first value is "1" so light up the first LED. The next value on the clock is "0" so do nothing ,the next is "1" so light up the second LED etc etc.

so after the circuit is working correctly I could change the light sequence and the timer sequence to whatever I want, ie Light sequence (1,2,4,16,8,32,16,8,16,2) and the timer to (1,0,0,1,1,0,1)

Does this make sense smiley

Any pointers here?

Regards

Geoff
14  Using Arduino / Project Guidance / Re: Linear Stepper motor slider mechanism or ?? on: September 06, 2011, 01:30:47 pm
Ok, maybe I could half the duty cycle by doubling the motors, one moves one way then the other moves it back?

I looked at maybe using a rotating action into the linear but I think that the mechanism would be too big?

Regards

Geoff
15  Using Arduino / Project Guidance / Re: Linear Stepper motor slider mechanism or ?? on: September 04, 2011, 12:28:45 pm
I basically want to do this but with a 60mm stroke.



Regards

Geoff
Pages: [1] 2 3 4