I truely appreciate what you have done and in such a small space of time, I've been doing this for ages and it still dosn't work LOL.
You have used keywords I've not heard of yet "const int", "sizeof" so at the moment I'm a little bit confused as to how it's working but give me a couple of days and i will work it out.
I can't tell you how much i appreciate everyones help and to you "Camsysca" for writing this code.
Here's mostly @camsysca's code plopped into the wokwi simulator. If you didn't know, now you know. See it here
Da code
// https://wokwi.com/projects/422350080049242113
const int LEDpins[] = {2, 3, 4, 5}; //create an array of pin numbers
const int LEDpincount = sizeof LEDpins / sizeof *LEDpins; //calculate the size for use later
const int ON = HIGH; //defines the LED conditions in terms of output pin state
const int OFF = LOW;
int litestate[][LEDpincount] = //defines your states. Remember, if the number of pins changes, the number of columns will need changing
{
{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1},
{1, 1, 0, 0},
{1, 0, 1, 0},
{1, 0, 0, 1},
{0, 1, 1, 0},
{0, 1, 0, 1},
{0, 0, 1, 1},
{1, 1, 1, 0},
{1, 1, 1, 1}
};
const int states = sizeof litestate / sizeof *litestate; //calculate number of random states created
void setup() {
for (int ii = 0; ii < LEDpincount; ii++) { //loop through pin array
pinMode(LEDpins[ii], OUTPUT); //sets the mode of every LED pin
digitalWrite(LEDpins[ii], OFF); //not essential, but shuts off all LEDs to start with
}
}
void loop() {
int row = random(0, states);// since second limit is exclusive, we will never get states as a value, just states to states-1
for (int column = 0; column < LEDpincount; column++) {
digitalWrite(LEDpins[column],litestate[row][column]); //access the correct state for the row:pin desired
delay(166);
}
}
HTH
a7
// Varibles
int smokecount = 0;
int colum = 0;
int row = 0;
int state = 0;
int lite = 0;
// disco light PIN No's
int disco1 = 2;
int disco2 = 3;
int laser = 4;
int largedisco = 5;
int Strobe = 6;
int smokemachine = 7;
int path = 8;
// My 2D array
int litestate[11] [3] =
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1},
{1,1,0,0},
{1,0,1,0},
{1,0,0,1},
{0,1,1,0},
{0,1,0,1},
{0,0,1,1},
{1,1,1,0},
{1,1,1,1};
void setup()
{
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
row = random(0,11);
for (colum = 0; colum <= 3; colum++);
{
state = litestate[row] [colum];
digitalWrite(colum, state);
}
smokecount = smokecount +1;
if (smokecount = 5);
{
smokecount=0;
digitalWrite(smokemachine, LOW);
digitalWrite(Strobe, LOW);
delay (3000);
digitalWrite(smokemachine, HIGH);
digitalWrite(Strobe, HIGH);
}
delay (10000);
}
this is my code, Not as good as yours. my excuse is Only just started in Arduino
My idea is this...
I have four disco lights and want them to come on randomly, the 0 &1 are all the combinations.
the path light comes on from the start and stays on, the strobe only comes on with the smokemachine.
the smokemachine can only stay on for 30 seconds till the smoke runs out, then has to replenish it's self.
Sorry if the explination isn't understandable
Careful. Programming is a bitch sometimes.
Here you have two errors that aren't even going to be flagged as errors!
if (smokecount = 5);
First, = is for assignment, == is a test for equality. The condition tested is 5, 5 is nonzero hence true, so the state,ent will always be execute.
But what is the guarded statement? That pesky semicolon. It is the end of the if statement. There is no code being conditionally executed. The code { block } that follows is not part of that, and will execute unconditionally.
In the IDE preferences, turn up the verbosity and warning levels. I think at least one of those mistakes that aren't always mistakes would elicit a warning. Warnings come when the compi,er likes what it sees OK but has some reason to think you don't know what you are doing.
Those errors are too easy to miss and can be hard to find.
a7
@franitauk lucky you, to run into another place where numbers aren't what you think they might be.
row = random(0,11);
will never return 11. The upper limit is not included. To randomly grab one of 12 things, you do want the nubers 0, 1, 2,…, 11, so you must
row = random(0, 12);
Some of this stuff is hard until it is easy. Don't fret, we all started nowhere.
a7
Thank you Alto777, for pointing out my mistakes. I used to program in "BASIC" years ago(30+). I heard about Arduino and decided to give it a go, I think my problem is mixing the two together. I tried "Microsoft Basic" but hated it, it's the most confussing language I've used (or tried to use). I taught myself from books and computer magazines but my mind was a lot sharper then. it's slowed down now i'm 65 but I'll keep plodding on........
I'm sorry to be a nussance, but can someone please tell whats wrong with this code.....
I get "Too many initialisers for 'int[3]'
it has to be my array because thats the only 3 in []
// My 2D array
int litestate[11][3] =
{
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1},
{1,1,0,0},
{1,0,1,0},
{1,0,0,1},
{0,1,1,0},
{0,1,0,1},
{0,0,1,1},
{1,1,1,0},
{1,1,1,1}
}
Because you have 4 numbers in each row. .
Change 3 to 4...
And 11 to 12 (as you have 12 rows).
So you've chosen to ignore the PM thread you raised yesterday, in which I answered all of this and more?
Seriously. You must learn the difference between creating an array, in which the numbers used define the number of values in each row and column,(in this case, you've used 11 and 3) versus the indexing of that same array, in which case the indices range from 0 to 10 and 0 to 2. (which, of course, are incorrect - you need to initialize with [12][4] in order to use the array you've provided).
I watched for your reply yesterday after providing you with feedback, and then today, but you never picked up the message thread again. You seemed to be using a mix of email and web forum access.
Good luck!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.