How To

Hi Guys

Bit Of Help! please i'm completely new to the arduino language
how would i tell arduino to change from one script to another with out plugin into pc

i got 4 different scripts for 8 shift registers - 64 leds Knight rider-- led chaser--- and--- two random scripts
below is a shortened example of the script im using for all 4

any help most appreciated

int i, time = 1000;
void setup()
{
pinMode(2, OUTPUT);//data
pinMode(3, OUTPUT);//latch
pinMode(4, OUTPUT);//clock
}

void loop()
{
digitalWrite(3, LOW);
//shiftOut(dataPin, clockPin, bitOrder, value)
shiftOut(2, 4, MSBFIRST, 0); //shift register 8
shiftOut(2, 4, MSBFIRST, 0); //shift register 7
shiftOut(2, 4, MSBFIRST, 0); //shift register 6
shiftOut(2, 4, MSBFIRST, 1); //shift register 5
shiftOut(2, 4, MSBFIRST, 0); //shift register 4
shiftOut(2, 4, MSBFIRST, 0); //shift register 3
shiftOut(2, 4, MSBFIRST, 0); //shift register 2
shiftOut(2, 4, MSBFIRST, 1); //shift register 1
digitalWrite(3, HIGH);
delay(time);
digitalWrite(3, LOW);
//shiftOut(dataPin, clockPin, bitOrder, value)
shiftOut(2, 4, MSBFIRST, 0); //shift register 8
shiftOut(2, 4, MSBFIRST, 0); //shift register 7
shiftOut(2, 4, MSBFIRST, 0); //shift register 6
shiftOut(2, 4, MSBFIRST, 2); //shift register 5
shiftOut(2, 4, MSBFIRST, 0); //shift register 4
shiftOut(2, 4, MSBFIRST, 0); //shift register 3
shiftOut(2, 4, MSBFIRST, 0); //shift register 2
shiftOut(2, 4, MSBFIRST, 2); //shift register 1
digitalWrite(3, HIGH);
delay(time);
digitalWrite(3, LOW);
//shiftOut(dataPin, clockPin, bitOrder, value)
shiftOut(2, 4, MSBFIRST, 0); //shift register 8
shiftOut(2, 4, MSBFIRST, 0); //shift register 7
shiftOut(2, 4, MSBFIRST, 0); //shift register 6
shiftOut(2, 4, MSBFIRST, 4); //shift register 5
shiftOut(2, 4, MSBFIRST, 0); //shift register 4
shiftOut(2, 4, MSBFIRST, 0); //shift register 3
shiftOut(2, 4, MSBFIRST, 0); //shift register 2
shiftOut(2, 4, MSBFIRST, 4); //shift register 1
digitalWrite(3, HIGH);
delay(time);
digitalWrite(3, LOW);
}

got 4 different scripts

Write each one as a simple function.
In "loop" read a couple of input pins which tells your code which one of the four to call.

how would i tell arduino to change from one script to another with out plugin into pc

You can't. You can only have on sketch at a time installed on the Arduino.

how would i tell arduino to change from one script to another with out plugin into pc

You could have some button/switch that when pressed changes to the next pattern.

some pseudo code to get direction

#define BUTTON 6  // whatever

int scriptId = 0;

void setup()
{
  pinMode(BUTTON, INPUT);
  // rest of setup...
}

void loop()
{
  if (digitalRead(BUTTON) == HIGH) scriptId = scriptId + 1;
  if (scriptId > some max value) scriptID = 0;
  
  switch (scriptId)
  {
  case 0: pattern0(); break;
  case 1: pattern1(); break;
  case 2: pattern2(); break;
  case 3: pattern3(); break;
  default: break;
  }
}

void pattern0()
{
  .. all nice shifts for patter 0..
}

void pattern1()
{
  .. same as pattern0 but slightly different :)
}

etc...

Of course you could also make a selection with a potmeter connected to analog 0

int scriptId = map(analogRead(A0), 0, 1024, 0, 10); // selects between 10 scripts

hopes this helps
Rob

PaulS:

how would i tell arduino to change from one script to another with out plugin into pc

You can't. You can only have on sketch at a time installed on the Arduino.

AWOL:

got 4 different scripts

Write each one as a simple function.
In "loop" read a couple of input pins which tells your code which one of the four to call.

NEVER MIND IV'E FOUND MY HAMMER AND I NO LONGER OWN AN ARDUINO ]:smiley:

NEVER MIND IV'E FOUND MY HAMMER AND I NO LONGER OWN AN ARDUINO

Pity, you were so close ...

robtillaart:

NEVER MIND IV'E FOUND MY HAMMER AND I NO LONGER OWN AN ARDUINO

Pity, you were so close ...

Thanx for the code but out of curiosity and no ardiuno i tried your code and wouldn't verify 'some' was not declared in this scope

it may help others

Thanx

My code was pseudo code and it would need an amazingly good compiler to make a real executable from it (and that did what it supposed to)

On this forum people give other people mainly hints as they have their own projects to write. Most people love to find out themselves.
BTW there is a subforum under community for the commercial gigs :wink: if you want someone do it for you.