How do I slow this down?

Hi all,

really new to this. I have almost no idea what I'm doing. I have programmed a custom board with an ATtiny4313 chip. It is a light display that plays a sequence over and over again. It goes at a million miles an hour though and I don't know how to slow it down to say 2 seconds before it moves on. I've attached the code below so you could maybe tell me what part to change and to what to? I've tried changing where it says 'delay(0);' but the sequence messes up. Any help would be MUCH appreciated. I'm stumped!!!

/*
Boba Fett Chest Display Circuit
This is the software for the display on Boba Fett’s chest plate.
Lights are multiplexed. ATTINY4313

Last Modified: Jan 2, 2016

Authors: Joshua Kane, Dustin Westaby

Video Demo:
Imgur

Part List:
http://www.mouser.com/ProjectManager/ProjectDetail.aspx?AccessID=7c6a316116

PCB Main Board:
https://www.oshpark.com/shared_projects/ml5VjhuM

PCB Bargraph Board:
https://www.oshpark.com/shared_projects/E4qjCF4r

Usage:
Some example sequences are given below. For a customized sequence:

  • Download the Board Sequence Builder from fettronics.com
  • Edit the sequence builder's .ini file with the following:
    segmentorder=-gfedcba
    toporder=---12345
  • Open the Board Sequence Builder application and create your new sequence.
  • When finished, save, close, and reopen the .ini file. Find your sequence on the list.
  • Copy and paste the hex numbers below in the appropriate locations
  • Update NUM_STEPS with the number of lines in your animation sequence

*/

/* =========================
Structure Constants
========================= */

/* For ROTJ:

  • Change NUM_STEPS to 8
  • Copy and paste the following into char_sequence below:

const byte char_sequence[NUM_STEPS][NUM_DIGITS + 1] =
{
// DIGIT 1 DIGIT 2 DIGIT 3 DIGIT 4 DIGIT 5 BAR (0-4) DISPLAY BARGRAPH
// GFEDCBA GFEDCBA GFEDCBA GFEDCBA GFEDCBA 12345 01234
{0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0x03}, //Seq 1 - 88888 | = |
{0b10111101, 0b11011011, 0b11110110, 0b11001111, 0b10111110, 0xFF}, //Seq 2 - '.=¦= | |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x02}, //Seq 3 - dUEP' | = |
{0b10001001, 0b11000010, 0b10100100, 0b10000000, 0b11001110, 0xFF}, //Seq 4 - HG28r | |
{0b10001001, 0b10010010, 0b10100100, 0b10011000, 0b11111001, 0x00}, //Seq 5 - H5291 |= |
{0b10111101, 0b11011011, 0b11110110, 0b11001111, 0b10111110, 0xFF}, //Seq 6 - '.=¦= | |
{0b10001011, 0b10000110, 0b10001000, 0b10100001, 0b10001001, 0x04}, //Seq 7 - hEADH | =|
{0b10001001, 0b11000010, 0b10100100, 0b10000000, 0b11001110, 0xFF}, //Seq 8 - HG28r | |
};

For ESB:

  • Change NUM_STEPS to 11
  • Copy and paste the following into char_sequence below

const byte char_sequence[NUM_STEPS][NUM_DIGITS + 1] =
{
// DIGIT 1 DIGIT 2 DIGIT 3 DIGIT 4 DIGIT 5 BAR (0-4) DISPLAY BARGRAPH
// GFEDCBA GFEDCBA GFEDCBA GFEDCBA GFEDCBA 12345 01234
{0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0xFF}, //Seq 1 - | |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x01}, //Seq 2 - dUEP' | = |
{0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0x03}, //Seq 3 - 88888 | = |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x02}, //Seq 4 - dUEP' | = |
{0b10001011, 0b10000110, 0b10001000, 0b10100001, 0b10001001, 0x04}, //Seq 5 - hEADH | =|
{0b10111101, 0b11011011, 0b11110110, 0b11001111, 0b10111110, 0xFF}, //Seq 6 - '.=¦= | |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x01}, //Seq 7 - dUEP' | = |
{0b10001001, 0b10010010, 0b10100100, 0b10011000, 0b11111001, 0x00}, //Seq 8 - H5291 |= |
{0b10111101, 0b11011011, 0b11110110, 0b11001111, 0b10111110, 0xFF}, //Seq 9 - '.=¦= | |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x01}, //Seq 10 - dUEP' | = |
{0b10001001, 0b11000010, 0b10100100, 0b10000000, 0b11001110, 0xFF}, //Seq 11 - H{E8¬ | |
};

*/
#define NUM_STEPS 11

#define UPDATE_FREQUENCY 300 //approx 2 seconds

#define NUM_BARS 5
#define NUM_DIGITS 5
#define NUM_SEGMENTS 7

//this structure holds the entire sequence of characters to display
const byte char_sequence[NUM_STEPS][NUM_DIGITS + 1] =
{
// DIGIT 1 DIGIT 2 DIGIT 3 DIGIT 4 DIGIT 5 BAR (0-4) DISPLAY BARGRAPH
// GFEDCBA GFEDCBA GFEDCBA GFEDCBA GFEDCBA 12345 01234
{0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0xFF}, //Seq 1 - | |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x01}, //Seq 2 - dUEP' | = |
{0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0x03}, //Seq 3 - 88888 | = |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x02}, //Seq 4 - dUEP' | = |
{0b10001011, 0b10000110, 0b10001000, 0b10100001, 0b10001001, 0x04}, //Seq 5 - hEADH | =|
{0b10111101, 0b11011011, 0b11110110, 0b11001111, 0b10111110, 0xFF}, //Seq 6 - '.=¦= | |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x01}, //Seq 7 - dUEP' | = |
{0b10001001, 0b10010010, 0b10100100, 0b10011000, 0b11111001, 0x00}, //Seq 8 - H5291 |= |
{0b10111101, 0b11011011, 0b11110110, 0b11001111, 0b10111110, 0xFF}, //Seq 9 - '.=¦= | |
{0b10100001, 0b11000001, 0b10000110, 0b10001100, 0b11111101, 0x01}, //Seq 10 - dUEP' | = |
{0b10001001, 0b11000010, 0b10100100, 0b10000000, 0b11001110, 0xFF}, //Seq 11 - H{E8¬ | |
};

#define BAR_DATA NUM_DIGITS
#define BAR_ON LOW
#define BAR_OFF HIGH

// Setup PinMap for bars at the top of the kit
const byte pinmap_bars[5] =
{
11, // Bar 1
12, // Bar 2
13, // Bar 3
2, // Bar 4
3, // Bar 5
};

// Setup PinMap for the individual segements in each Character in the Kit
const byte pinmap_segments[7] =
{
0, // Segment A
1, // Segment B
4, // Segment C
5, // Segment D
6, // Segment E
7, // Segment F
8, // Segment G
};

// Setup PinMap that controls the selection of each Character in the Kit
const byte pinmap_digits[5] =
{
9, // Digit 1
10, // Digit 2
14, // Digit 3
15, // Digit 4
16, // Digit 5
};

// the setup routine runs once when you press reset:
void setup()
{
// Setup external pins for the BARs across the top
for (int i = 0; i < 5; i++)
{
pinMode( pinmap_bars*, OUTPUT);*
digitalWrite(pinmap_bars*, HIGH);
_
}*_

* // Setup external pins for the segemnt data*
* for (int i = 0; i < 7; i++)*
* {*
pinMode( pinmap_segments*, OUTPUT);
digitalWrite(pinmap_segments, HIGH);
_ }*_

* // Setup external pins for the segment selector*
* for (int i = 0; i < 5; i++)*
* {*
pinMode( pinmap_digits*, OUTPUT);
digitalWrite(pinmap_digits, LOW);
_ }
}
// the loop routine runs over and over again forever:
void loop()
{_

sentence_test();
_}
// Walks through the entire sentence, word by word, repeating each word*

// multiple times so that they mind perceives a roughly two second delay
// between each new word before the loop starts again.
void sentence_test()
{
* // Move through the words in the sentence one at a time*
* for ( int idxWord = 0; idxWord < NUM_STEPS; idxWord++)*
* {
// Repeat each word to meet the desired update frequency (300 = ~2 seconds)_

for ( int idxDelay = 0; idxDelay < NUM_STEPS; idxDelay++)
_ {_
word_test( idxWord ) ;
_ }
}
}
// Walks through each character in the specified word index, delaying*

// only 1/10th of a second between characters as to allow the mind
// to see the letter even though it's on only 1/5 of the time.
void word_test(int idxWord )
{
* // Turn on the correct bar*
* digitalWrite( pinmap_bars[char_sequence[idxWord][BAR_DATA]], BAR_ON ) ;*
* // Now, let's work on the word we would like to display _
for( int character = 0 ; character < NUM_DIGITS; character++ )
_ {_
int charValue = char_sequence[idxWord][character] ;*

* // Setup the character on the data lines first*
* for( int segment = 0 ; segment < NUM_SEGMENTS; segment++ )
digitalWrite( pinmap_segments[segment], ( charValue >> segment ) & 1 ) ;*

* // Turn the character on*
* digitalWrite( pinmap_digits[character], HIGH);*

* delay(0);*

* // Turn the character off*
* digitalWrite( pinmap_digits[character], LOW);
_ }*_

* // Turn the correct bar off*
* digitalWrite( pinmap_bars[char_sequence[idxWord][BAR_DATA]], BAR_OFF );
_}*_

Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.

Notice the italics? You didn't put that in did you. This is because your code was not posted correctly. Edit that post and put the code in code tags.

I've tried changing where it says 'delay(0);' but the sequence messes up.

Changing it to what?

Hi!
Am new to Arduino as well, so I'm not sure whether this will work - I can't even understand most of the statements in your code. But how I slow down my code when I'm executing it is just add a delay at the very end of the code. You could try adding a one or two second delay.
Hope this helps!

where it says 'delay(0);' but the sequence messes up. Any help would be MUCH appreciated. I'm stumped!!!
Yep, it's the italic which is causing the problem. It is really hard to cut and paste and change the font. Never mind...

Can you describe what is wrong with "sequence"?
Apparently there is some other delay , but inserting a delay between character on / off should work.
Actually setting it to zero is odd, that is why there must be some other delay , maybe not by delay function.

Jim

julyjim:
where it says 'delay(0);' but the sequence messes up. Any help would be MUCH appreciated. I'm stumped!!!
Yep, it's the italic which is causing the problem. It is really hard to cut and paste and change the font. Never mind...

You'll have to excuse Vaclavjulyjim - despite being told repeatedly across the various iterations of identity, s/he hasn't really grasped the significance of code tags (or quote tags, for that matter) and in particular how their absence turns the common subscript [i] into italics.

Copying and pasting incorrectly-posted code that has been mangled is not simply a matter of changing the font (we assume that Vaclavjulyjim knows this by now and is just being awkward for the Hell of it, or is simply being wilfully stupid, but it is really hard to tell), but rather the code has to be carefully analysed to see which variables have indices. That's effort for others.

This is why we ask people to post code in [code][/code] tags as a simple courtesy (link for Vaclavjulyjim) to other users.
After all, if you want help, you want to make it as easy as possible for others to help you, don't you?

It really helps if you make a 'clickable' link. Use the link icon (chain) in the posting menu.

If a link is not clickable, it takes too many steps on an iPad to go to the link, so I don't.

.

Howdy friend. I am the author of the code you pasted. I ahve an updated version here.

The reason it is going a million miles an hour is your DIV8 fuse. The code assumes that the arduino is running at 1Mhz.

If your arduino is 8Mhz, adjust the timing like so:

#define NUM_LOOPS_PER_WORD 300*8