Go Down

Topic: Newbie needs assistance (Read 43555 times) previous topic - next topic

Grumpy_Mike

Quote
does that sound right?

No.

Quote
one shiftregister per catagory of lighting with its capacity expanded to accomodate the led quantity for that cagatory. But using the chip Fungus said

There is only one place you can connect a TLC5940 to an arduino, if you want more you will have to chain them.

Quote
Each shift register assigned to a specific output on the arduino.

No that is not the way it works so you can use a shift register and dim them, unless you want to re write the shiftPWM libary then you can't do it.

secretreeve

#16
Dec 21, 2012, 03:09 pm Last Edit: Dec 21, 2012, 03:36 pm by secretreeve Reason: 1
Then perhaps instead of just saying "no" you can elaborate somewhat on things.

Do you talk down to all new people to this? Or are you just sour? So far all I have seen is one useful link and no no no.

It would be extremely helpful if you explained the best way to lay out the stages as thats the first part and frankly I dont know where to start.

I dont have access to the board right now but I do have access to the programing software. I would just like to get a start on this while I wait for the board to come.

Its really not so much to ask now that someone points me in the direction of where to start and how to group stage 2 together.

Funny thing about software, it's not always dependant on you having the relevant hardware immediately.

Still cant work out if by rewrite the shiftregistry you mean bung that on an arduino and write the entire program into the shiftregistry or what.

In all honestly, I'm wondering if arduino is even the right platform for this in terms of keeping it simple.

fungus


Fungus, thats awesome. thank you. I assume that can be made to control the LEDs on the pin outs in a certain order or all together? Not used that chip before so it will be new, I have the data sheet to read through today for it though.


Each LED is individually controlled. Use the library.

You connect all the TLC5940s together as a chain, they're designed that way.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

dhenry

You probably want to go through the list and figure out what basic functions are required and look into your hardware to see how that can be achieved.

For example, you seem to need to turn on / off lights, fade lights, turn on / off motors, control timing, etc.

I would suggest that you expand that light and then assemble them together to perform individual stages.

Take this as an example. Let's say that your led is active low. You can write an led on/off function like this:

Code: [Select]


#define LED_ON(pin) digitalWrite(pin, LOW) //turn on an led, active low
#define LED_OFF(pin) digitalWrite(pin, HIGH) //turn off an led, active low
#define LED_BLINK(pin, duration) do {LED_ON(pin); delay(duration); LED_OFF(pin);} while (0) //blink a pin for a given duration

//perform stage 1 activities
void stage1(void) {
 LED_ON(LED_ORANGE); //turn on orange led
 LED_OFF(LED_RED); //turn off red led
 MOTOR_ON(FLIGHT_DECK); //turn on flight deck motor
 delay(DURATION_1s); //for a second
 MOTOR_OFF(FLIGHT_DECK); //turn off flight deck, after a second
 for (i=0; i<20; i++) LED_BLINK(LED_FLIGHT, 100); //flash flight led for 20 times x 100ms
 ...
}


Just some examples.

Think of programming as building a house with lego blocks: you have to figure out what those little blocks are and then assemble them together.

secretreeve

Dhenry, that is fantastic!

That gives me some idea on where to start so I VERY much thank you as it's exactly what I was needing, that little nudge in the direction of the beginning!

I'll take a look into the arduino software and see what I can come up with.

Just breeze over this quickly, does someone have a link to adding push button controls that I can bookmark for later?

I'll have a bash at knocking something together and post it up. See if I'm along the right track there.

Although I do still have questions about expanding the arduino.

Ideally I would like to be able to add a board to each channel which basically just allows me to up the number of LEDS per channel without IC's and so on. So the channel on the arduino would act more like a signal to the "booster board".

That shouldnt be too difficult should it?

secretreeve

Having a bit of trouble defining the duration for delay.

basically the delay between events.

Could someone tell me how to define that so it recognises
Code: [Select]
delay (duration_1s) as a 1 second pause between events?

fungus


I'll have a bash at knocking something together and post it up. See if I'm along the right track there.


Please do...


That shouldnt be too difficult should it?


You're the expert.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

fungus


Could someone tell me how to define that so it recognises
Code: [Select]
delay (duration_1s) as a 1 second pause between events?


Maybe you could read the documentation for 'delay()'.

Oh, wait, I forgot. You don't have time to sit there learning before you start programming.


No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

retrolefty


Having a bit of trouble defining the duration for delay.

basically the delay between events.

Could someone tell me how to define that so it recognises
Code: [Select]
delay (duration_1s) as a 1 second pause between events?

first you would have to assign a value to the duration_1s variable, usually in your setup function, other wise it defaults to 0 on startup. The name implies it should be defined as a constant variable.

const int duration_1s = 1000;   //1000 milliseconds = 1 second

Lefty

secretreeve

#24
Dec 21, 2012, 05:19 pm Last Edit: Dec 21, 2012, 05:32 pm by secretreeve Reason: 1
Okay, heres what i got so far, I know the pin values will be wrong for some of these and will need adjusting at a later date. As well as digitalWrite and analogeWrite.

And I'm fully expecting this to be so full of errors bill gates would have a heart attack.

Code: [Select]
#define LED_ON(pin) digitalWrite(pin, LOW) //turn on an led, active low
#define LED_OFF(pin) digitalWrite(pin, HIGH) //turn off an led, active low
#define LED_BLINK(pin, duration) do {LED_ON(pin); delay(duration); LED_OFF(pin);} while (0) //blink a pin for a given duration
#define PRIMARY_ON digitalWrite (1, LOW)
#define PRIMARY_OFF digitalWrite (1, HIGH)
#define SECONDARY_ON digitalWrite (2, LOW)
#define SECONDARY_OFF digitalWrite (2, HIGH)
int brightness = 5;
int fadeAmount = 5;
#define IMPULSE_ON digitalWrite (3, HIGH)
#define IMPULSE_OFF digitalWrite (3, LOW)
#define SHUTTLEBAY_ON digitalWrite (4, HIGH)
#define SHUTTLEBAY_OFF digitalWrite (4, LOW)
#define SHUTTLEBAYDOOR_ON digitalWrite (5, HIGH)
#define SHUTTLEBAYDOOR_OFF digitalWrite (5, LOW)
#define RCSTHRUSTERS_ON digitalWrite (6, HIGH)
#define RCSTHRUSTERS_OFF digitalWrite (6, LOW)
#define FLOODLIGHTS_ON digitalWrite (7, HIGH)
#define FLOODLIGHTS_OFF digitalWrite (7, LOW)
#define NAGIVATION_ON digitalWrite (8, HIGH)
#define NAVIGATION_OFF digitalWrite (8, LOW)
#define STROBES_ON digitalWrite (9, HIGH)
#define STROBES_OFF digitalWrite (9, LOW)
#define DEFLECTORORANGE_ON digitalWrite (10, HIGH)
#define DEFLECTORORANGE_OFF digitalWrite (10, LOW)
#define DEFLECTORBLUE_ON digitalWrite (11, HIGH)
#define DEFLECTORBLUE_OFF digitalWrite (11, LOW)
#define NECELLS_ON digitalWrite (12, HIGH)
#define NECELLS_OFF digitalWrite (12, LOW)
const int duration_1s = 1000;
#define TORPEDOS_ON digitalWrite (13, HIGH)
#define TORPEDOS_OFF digitalWrite (13, LOW)
#define SHUTTLEBAYLANDING_ON digitalWrite (14, HIGH)
#define SHUTTLEBAYLANDING_OFF digitalWrite (14, LOW)


//perform stage 1 activities
void stage1(void) {
 PRIMARY_ON;
 delay (duration_1s);
 SECONDARY_ON);
 delay (duration_1s)
 DEFLECTORORANGE_ON (brightness, 3)
 delay (duration_2s)
 NECELLS_ON
 delay (brightness_1s)
 IMPULSE_ON (brightness, 3)
 delay (duration_2s)
 SHUTTLEBAY_ON
 delay (duration_1s)
 SHUTTLEBAYDOOR_ON
 delay (duration_5s)
 SHUTTLEBAYDOOR_OFF
 SHUTTLEBAYLANDING_ON
 delay (duration 1s)
 RCSTHRUSTERS_ON (brightness, 3)
 delay (duration, 2s)
 FLOODLIGHTS_ON
 delay (duration, 1s)
 NAVIGATION_ON
 delay (duration, 1s)
 STROBES_ON
 delay (duration, 1s)
 TORPEDOS_ON (brightness, 3)


Supposed to achieve this:

Start up sequence
primary hull - immediatly on
secondary hull - immediatly on
deflector dish - fade on to standby 2 second fade to 100%
necells - N/A
Impulse - Fade on "standby" 2 second fade to 100%
Shuttle bay fade on 4 second fade to 100%
RCS thrusters - fade on 50% brightness
Flood lights immediatly on
Torpedo launchers - Immediatly on
Shuttle bay doors open
Shuttle bay landing strip lights activate

end program

My main concern is "Enterprise_program:41: error: expected `;' before 'digitalWrite'"

If I fix that, it will come up for the remainder, but if I can fix one, then I can fix the rest, to google!


figured that bit out.

dhenry

Quote
heres what i got so far


I would do it slightly differently:

Code: [Select]

#define DIGITAL_ON(pin) digitalWrite(pin, LOW) //digital on, active low
#define DIGITAL_OFF(pin) digitalWrite(pin, HIGH) //digital off, active low

//define pins
#define PRIMARY 1 //primary on pin 1
#define SECONDARY 2 //secondary on pin2
#define IMPULSE 3 //impulse on pin 3
#define SHUTTLEBAY 4 //shuttlebase on pin 4
...

//pin functions
#define PRIMARY_ON() DIGITAL_ON(PRIMARY) //turn primary on active low
#define PRIMARY_OFF() DIGITAL_OFF(PRIMARY) //turn primary off
...
#define SHUTTLEBAY_ON() DIGITAL_OFF(SHUTTLEBAY) //turn shuttlebay on, active high
#define SHUTTLEBAY_OFF() DIGITAL_ON(SHUTTLEBAY) //turn shuttlebay off, active high
...

void stage1(void) {
  PRIMARY_ON(); //turn on primary
  SHUTTLEBAY_OFF(); //turn off shuttlebay
...
}


What it does is to predefine a set of pins so that if you change pin connection in the future, all you do is to change the defines and recompile, your code will work.

Hard coding pin connections, as you did, is a really bad practice.

secretreeve

Revised code

Code: [Select]
#define LED_ON(pin) digitalWrite(pin, LOW) //turn on an led, active low
#define LED_OFF(pin) digitalWrite(pin, HIGH) //turn off an led, active low
#define LED_BLINK(pin, duration) do {LED_ON(pin); delay(duration); LED_OFF(pin);} while (0) //blink a pin for a given duration
#define PRIMARY_ON digitalWrite (1, LOW)
#define PRIMARY_OFF digitalWrite (1, HIGH)
#define SECONDARY_ON digitalWrite (2, LOW)
#define SECONDARY_OFF digitalWrite (2, HIGH)
int brightness = 5;
int fadeAmount = 5;
#define IMPULSE_ON digitalWrite (3, HIGH)
#define IMPULSE_OFF digitalWrite (3, LOW)
#define SHUTTLEBAY_ON digitalWrite (4, HIGH)
#define SHUTTLEBAY_OFF digitalWrite (4, LOW)
#define SHUTTLEBAYDOOR_ON digitalWrite (5, HIGH)
#define SHUTTLEBAYDOOR_OFF digitalWrite (5, LOW)
#define RCSTHRUSTERS_ON digitalWrite (6, HIGH)
#define RCSTHRUSTERS_OFF digitalWrite (6, LOW)
#define FLOODLIGHTS_ON digitalWrite (7, HIGH)
#define FLOODLIGHTS_OFF digitalWrite (7, LOW)
#define NAVIGATION_ON digitalWrite (8, HIGH)
#define NAVIGATION_OFF digitalWrite (8, LOW)
#define STROBES_ON digitalWrite (9, HIGH)
#define STROBES_OFF digitalWrite (9, LOW)
#define DEFLECTORORANGE_ON digitalWrite (10, HIGH)
#define DEFLECTORORANGE_OFF digitalWrite (10, LOW)
#define DEFLECTORBLUE_ON digitalWrite (11, HIGH)
#define DEFLECTORBLUE_OFF digitalWrite (11, LOW)
#define NECELLS_ON digitalWrite (12, HIGH)
#define NECELLS_OFF digitalWrite (12, LOW)
const int duration_1s = 1000;
const int duration_2s = 2000;
const int duration_3s = 3000;
const int duration_4s = 4000;
const int duration_5s = 5000;
#define TORPEDOS_ON digitalWrite (13, HIGH)
#define TORPEDOS_OFF digitalWrite (13, LOW)
#define SHUTTLEBAYLANDING_ON digitalWrite (14, HIGH)
#define SHUTTLEBAYLANDING_OFF digitalWrite (14, LOW)


//perform stage 1 activities
void stage1(void) {
  PRIMARY_ON;
  delay (duration_1s);
  SECONDARY_ON;
  delay (duration_1s);
  DEFLECTORORANGE_ON (brightness, 3);
  delay (duration_2s);
  NECELLS_OFF;
  IMPULSE_ON (brightness, 3);
  delay (duration_2s);
  SHUTTLEBAY_ON;
  delay (duration_1s);
  SHUTTLEBAYDOOR_ON;
  delay (duration_5s);
  SHUTTLEBAYDOOR_OFF;
  SHUTTLEBAYLANDING_ON;
  delay (duration_1s);
  RCSTHRUSTERS_ON (brightness, 3);
  delay (duration_2s);
  FLOODLIGHTS_ON;
  delay (duration_1s);
  NAVIGATION_ON;
  delay (duration_1s);
  STROBES_ON;
  delay (duration_1s);
  TORPEDOS_ON (brightness, 3)}


However I do have this:

Code: [Select]
Enterprise_program:47: error: void value not ignored as it ought to be
Enterprise_program:50: error: void value not ignored as it ought to be
Enterprise_program:59: error: void value not ignored as it ought to be
Enterprise_program:67: error: void value not ignored as it ought to be
Enterprise_program:67: error: void value not ignored as it ought to be
Enterprise_program.ino: At global scope:

secretreeve


Quote
heres what i got so far


I would do it slightly differently:

Code: [Select]

#define DIGITAL_ON(pin) digitalWrite(pin, LOW) //digital on, active low
#define DIGITAL_OFF(pin) digitalWrite(pin, HIGH) //digital off, active low

//define pins
#define PRIMARY 1 //primary on pin 1
#define SECONDARY 2 //secondary on pin2
#define IMPULSE 3 //impulse on pin 3
#define SHUTTLEBAY 4 //shuttlebase on pin 4
...

//pin functions
#define PRIMARY_ON() DIGITAL_ON(PRIMARY) //turn primary on active low
#define PRIMARY_OFF() DIGITAL_OFF(PRIMARY) //turn primary off
...
#define SHUTTLEBAY_ON() DIGITAL_OFF(SHUTTLEBAY) //turn shuttlebay on, active high
#define SHUTTLEBAY_OFF() DIGITAL_ON(SHUTTLEBAY) //turn shuttlebay off, active high
...

void stage1(void) {
  PRIMARY_ON(); //turn on primary
  SHUTTLEBAY_OFF(); //turn off shuttlebay
...
}


What it does is to predefine a set of pins so that if you change pin connection in the future, all you do is to change the defines and recompile, your code will work.

Hard coding pin connections, as you did, is a really bad practice.



I see, that would make future changes alot easier as once the hardware arrives and is assembled im sure there will be alot of pin changes.

What do you think to the errors in my previous post? Havent had a change to google it yet as wanted to see if I was travelling the right path or not before going to much further.

Judging by you only mentioning changing how the pins are coded, I assume the rest is looking alright once the pins are...."soft coded"? not sure if thats the right term haha.

dhenry

You will need to figure out what those lines are before you can fix them.

Code: [Select]

const int duration_1s = 1000;
const int duration_2s = 2000;
const int duration_3s = 3000;
const int duration_4s = 4000;
const int duration_5s = 5000;


I would change that slightly:

Code: [Select]

#define duration_1s 1000ul //define 1 second, in ms
#define duration_2s (duration_1s * 2) //2 second delay
#define duration_3s (duration_1s * 3) //3 second delay

...


So if you never need to change duration_1s (say on a different platform), the other duration parameters are automatically adjusted.

dhenry

Another tip that I find help.

I tend to program top-down: meaning that I put high level functional blocks in my code and then implement them individually.

Like in your case, I would do this:

Code: [Select]

//define pins here
...

//define major macros here
...

//define major blocks here
//keep them empty for now
void stage1(void) {
}

void stage2(void) {
}

void stage3(void) {
}
...

//code starts here

void setup(void) {
  //initialize my module
}

void loop(void) {
  stage1();
  stage2();
  if (executing_stage3()) stage3(); //conditional execute stage 3
}


Once I have the framework setup, I would implement individual blocks, again, top down.

I find that easier for me.

Go Up