Offline
Newbie
Karma: 0
Posts: 43
|
 |
« on: July 20, 2012, 09:13:49 pm » |
I am not really sure what I need just yet. I only have about 3 days under my belt with the arduino. What I am looking to do is blink a pair of LED's at one rate while blinking another pair at a different rate. What I have now is using delay functions and it makes it go through the whole sequence before it starts again which isn't working. I want to blink lights like in a police car. The red and blue go fast and the headlights blink slowly (wig,wag). I think it would be a good learning project but I haven't found anything similar yet online to look at. Just a nudge in the right direction would be appreciated. It's taking longer to pick this up than I thought, I am not 20 anymore darn it. LOL....  Thank you all. Andrew
|
|
|
|
|
Logged
|
|
|
|
|
California
Offline
Edison Member
Karma: 50
Posts: 2157
|
 |
« Reply #1 on: July 20, 2012, 09:18:05 pm » |
Look at the Blink Without Delay example.
|
|
|
|
|
Logged
|
|
|
|
|
Austin, TX
Offline
Faraday Member
Karma: 42
Posts: 5242
CMiYC
|
 |
« Reply #2 on: July 20, 2012, 09:46:36 pm » |
After looking at blink without delay, look at this tutorial I wrote on millis(), which shows how to blink 2 LEDs at different rates: http://www.cmiyc.com/blog/2011/01/06/millis-tutorial/
|
|
|
|
|
Logged
|
|
|
|
|
Sydney
Offline
God Member
Karma: 15
Posts: 743
Big things come in large packages
|
 |
« Reply #3 on: July 20, 2012, 10:50:46 pm » |
And just to add another, you can look at MultiBlink. This is probably a bit challenging at your level of understanding, but it will stretch your thinking.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #4 on: July 22, 2012, 07:55:46 pm » |
Thanks Gents. I will look and try to learn as I read. I appreciate your replies, thank you.
Andrew
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #5 on: July 23, 2012, 12:41:24 pm » |
Hey Marco-C I am looking at that multibink. But I think it needs a library MultiBlink.h ?? Where do I get that or how does that work...you are right that is very new for me..but hey I can maybe learn about it now.
Thank you.
Andrew
|
|
|
|
|
Logged
|
|
|
|
|
Sydney
Offline
God Member
Karma: 15
Posts: 743
Big things come in large packages
|
 |
« Reply #6 on: July 23, 2012, 03:27:38 pm » |
The header file is part of the posting. You will need to split them as there was no easy way to do that in the playground. It is the first part of the code up to the #endif, as per the comments in the program.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #7 on: August 28, 2012, 08:06:30 am » |
So I saved the header file as a .h in the directory of the sketch. But now the sketch won't compile as it doesn't like the table T..says <Multi_blink:47: error: 'T' was not declared in this scope" what do I need to modify in this line?? Also if you say that it needs to go into the sketch dir, well I can't find it..tried many things..it's not in the documents and I don't see one where it should be..I know it's obviously around somewhere but I can't find it. It's supposed to work with the .ino file right??
Andrew
|
|
|
|
|
Logged
|
|
|
|
|
New Hampshire
Offline
God Member
Karma: 13
Posts: 776
There are 10 kinds of people, those who know binary, and those who don't.
|
 |
« Reply #8 on: August 28, 2012, 09:38:21 am » |
Post your code. We can't tell you what you did wrong without seeing what you did. Sounds like you aren't properly declaring your LedTable T, but that's just a guess without any code to look at.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #9 on: August 28, 2012, 10:42:46 am » |
It wasn't my code it is from the Muilti_Blink on the play ground. Everyone seemed so aware of it I didn't post. But here it is. / Multi_Blink // // Blink lots of LEDs at different frequencies simultaneously // // Marco Colli - May 2012 // // Demonstrates the way to carry out multiple time based tasks without using the delay() function // Demonstrates the use of structures (and structures within structures) // Demonstrates a data driven approach to programming to create compact, reusable code //
#include "Multi_Blink.h" // type definitions
// Blink Table T - Modify this table to suit whatever the output requirements are // Add or delete lines as required to achieve the desired effects. // ledTable T[] = // THIS LINE HERE //Pin St State 0 State 1 LastTime { { 3, 0, {{HIGH, 300}, {LOW, 300}}, 0 }, { 4, 1, {{HIGH, 300}, {LOW, 600}}, 0 }, { 5, 0, {{HIGH, 500}, {LOW, 500}}, 0 }, { 6, 1, {{HIGH, 50}, {LOW, 100}}, 0 }, { 7, 0, {{HIGH, 100}, {LOW, 50}}, 0 }, { 8, 1, {{HIGH, 500}, {LOW, 500}}, 0 }, { 9, 0, {{HIGH, 400}, {LOW, 600}}, 0 }, {10, 0, {{HIGH, 600}, {LOW, 400}}, 0 }, };
// Self adjusting constants for loop indexes #define MAX_STATE (sizeof(T[0].state)/sizeof(stateDef)) #define MAX_LED (sizeof(T)/sizeof(ledTable))
void setup() { for (int i=0; i < MAX_LED; i++) { pinMode(T[i].ledPin, OUTPUT);
T[i].lastTransTime = millis(); digitalWrite(T[i].ledPin, T[i].state[T[i].currentState].activeVal); } }
void loop() { for (int i=0; i < MAX_LED; i++) { // check if the state active time has expired (ie, it is less than current time) if (millis() >= T[i].lastTransTime + T[i].state[T[i].currentState].activeTime) { // switch to the next state with wrapround T[i].currentState = (T[i].currentState + 1) % MAX_STATE;
// write out the next state value T[i].lastTransTime = millis(); digitalWrite(T[i].ledPin, T[i].state[T[i].currentState].activeVal); } } } Moderator edit: [code] ... [/code] tags added. (Nick Gammon)
|
|
|
|
« Last Edit: September 04, 2012, 04:49:10 am by Nick Gammon »
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 142
Posts: 19339
I don't think you connected the grounds, Dave.
|
 |
« Reply #10 on: August 28, 2012, 11:26:43 am » |
If you put code tags around it, we'll be able to read it as you intended.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #11 on: August 28, 2012, 01:18:42 pm » |
I'll look for code tags, but that what I intended. It works now I guess I needed to restart the sketch or arduino. I tried to add more lines but it won't work it says ulti_blink:22: error: too many initializers for 'stateDef [2]'" As I modified the line to read.. { 5, 0, {{HIGH, 100}, {LOW, 100}, {HIGH, 100}, {LOW, 100}}, 0 },
Can you not do that? I want to make the LED flash quickly 3 times then wait as another LED flashes the same , then back.
|
|
|
|
|
Logged
|
|
|
|
|
New Hampshire
Offline
God Member
Karma: 13
Posts: 776
There are 10 kinds of people, those who know binary, and those who don't.
|
 |
« Reply #12 on: August 28, 2012, 01:33:57 pm » |
I'll look for code tags, but that what I intended. It works now I guess I needed to restart the sketch or arduino. I tried to add more lines but it won't work it says ulti_blink:22: error: too many initializers for 'stateDef [2]'" As I modified the line to read.. { 5, 0, {{HIGH, 100}, {LOW, 100}, {HIGH, 100}, {LOW, 100}}, 0 },
Can you not do that? I want to make the LED flash quickly 3 times then wait as another LED flashes the same , then back.
No, you can not do that. Statedef is a struct that declares two fields, a state (either HIGH or LOW) and a duration. LedTable is another struct that declares a statedef array of two elements, so you can't put more than 2 elements into it, and you are trying to put 4 in. Multiblink isn't really suited to what you want to do because it's designed to flash multiple LEDs completely asynchronously, and you want synchronous behavior.
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3117
|
 |
« Reply #13 on: August 28, 2012, 01:40:02 pm » |
I'll look for code tags, but that what I intended. You intended it to turn to italics two thirds of the way through?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 43
|
 |
« Reply #14 on: August 28, 2012, 02:02:59 pm » |
Ha, no I did not dxwood. Well taken. I meant the code looked as it was right to me. Formatting aside.
jraskell, what do you suggest? I thought multiblink was exactly what I wanted as the LED's don't have to have any relation at all except for in pairs. Such as two blink back and forth or two blink fast then off as the other blinks.
I would welcome any code help at all. Thanks for your replies.
|
|
|
|
|
Logged
|
|
|
|
|
|