Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:42:18+00:00 2026-06-17T16:42:18+00:00

I am making a persistence of vision display using an ATTiny85, programmed with Arduino

  • 0

I am making a persistence of vision display using an ATTiny85, programmed with Arduino using the arduino-tiny core.

It consists of a stick with 16 LEDs on it which is spun round quickly to ‘draw’ a picture in the air. The display buffer is represented by an array, the next index of which is output every time the timer fires. It uses a hall sensor wired to INT0 to sense top dead centre, where it zeroes the array index.

It is an 8 bit processor and I have 16 LEDs connected to LED drivers, so I actually use two arrays for the display.

So the weird thing is that when I initialised the display with a cross pattern, it displayed a bunch of broken lines; so I zeroed it first in case memory had some random stuff in it. Now it doesn’t display anything (even though I write the cross pattern to it straight after zeroing it). I have no idea what is happening, any ideas?

I had it previously outputting just the index value, and the picture it traces appears to look like counting binary, so I think the hardware is working.

Note that I’m not using digitalWrite because it disables interrupts which might throw the timing off.

Here is the code: (sorry it’s quite a lot)

#define COLUMNCOUNT 180

const int datapin = 4;
const int clockpin = 0;
const int latchpin = 1;
const int rxpin = 3;
const int hallpin = 2;

volatile int columns0[COLUMNCOUNT];
volatile int columns1[COLUMNCOUNT];
volatile int counter = 0;

void setup()
{
  pinMode(datapin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(latchpin, OUTPUT);
  pinMode(rxpin, INPUT);
  pinMode(hallpin, INPUT);


  //make sure the arrays are all zeroed
  for (int i = 0; i < COLUMNCOUNT; i++)
  {
    columns0[i] = 0;
    columns1[i] = 0;
  }

  //make a cross pattern
  columns0[0] = 255;
  columns1[0] = 255;
  columns0[45] = 255;
  columns1[45] = 255;
  columns0[90] = 255;
  columns1[90] = 255;
  columns0[135] = 255;
  columns1[135] = 255;

  //turn on the timer (prescale CK/16)
  OCR1A = 255;
  OCR1C = 255;
  TCNT1 = 0;
  TIMSK = _BV(OCIE1A);
  TCCR1 = _BV(CTC1) | _BV(CS12) | _BV(CS10);

  GIMSK = _BV(INT0);

  sei();
}

void loop()
{
  //nothing to do here
}


ISR(TIMER1_COMPA_vect)
{
   if (counter < COLUMNCOUNT)
     counter++;

   outputWord(columns0[counter], columns1[counter]);
}


ISR(INT0_vect)
{
  counter = 0;
}


void outputByte(int b)
{
  int currentBit;

  for (int i = 0; i < 8; i++)
  {
    currentBit = (b & 128) == 128;
    PORTB = _BV(clockpin) | (currentBit ? _BV(datapin) : 0);
    PORTB = PORTB ^ _BV(clockpin);

    b <<= 1;
  }
}


void outputWord(int hi, int lo)
{
  outputByte(hi);
  outputByte(lo);
  PORTB = _BV(latchpin);
  PORTB = 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:42:19+00:00Added an answer on June 17, 2026 at 4:42 pm

    Per C standard, global variables are initialised to 0. As such,

    //make sure the arrays are all zeroed
    for (int i = 0; i < COLUMNCOUNT; i++)
    {
      columns0[i] = 0;
      columns1[i] = 0;
    }
    

    is not necessary. That action is taken care of automatically when the __do_clear_bss section is executed.

    Also, as per C standard, the int type must be at least 16 bits wide. In AVR, the minimum is used. If you are using the free software toolchain, it contains inttypes.h which provides the functionality offered by stdint.h and some extra stuff. This was mentioned in another answer.

    The statement:

    PORTB = PORTB ^ _BV(clockpin);
    

    can be rewritten as:

    PINB = _BV(clockpin);
    

    which compiles to only 1 instruction, as per Atmel’s datasheets.

    Macros provided by pgmspace.h can read from flash. Notice that you can not change the contents of flash as your program runs in most AVR chips.

    Beware local/global variables and stack/heap collisions when handling this much data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm making a web app using mongoDB for the persistence later, I was
Making an adobe flex ui in which data that is calculated must use proprietary
I am making a application in which I am storing many dates in long
I'm making an application currently and I've started from creating a DB schema, which
I'm making an MSN client in PHP. I have this code, which connects to
i am making a sample program in hibernate follow this tutorial: http://www.myeclipseide.com/documentation/quickstarts/hibernateintroduction/ using reverse
Ok so I'm making a simple web app using the technologies from the topic,
I'm prototyping a simple sports sim game for iPhone which will use Core data.
I want to use SQLite for object persistence in C++ for making games (I'm
I'm thinking about making my own IUnitOfWork implementation for an NHibernate persistence layer. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.