I really need help [learning to code]! >-<

I’m going to base some code off of @emutyworks’s post and combine it with mine that I just posted.

#include "Arduboy.h"

Arduboy arduboy;

PROGMEM const unsigned char frameone[] =
{
	0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
	0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
	0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
};

PROGMEM const unsigned char frametwo[] =
{
	0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
	0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
	0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
};

PROGMEM const unsigned char framethree[] =
{
	0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
	0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
	0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
};

int counter = 0;
int frame = 0;

void setup() {
	arduboy.start();
	arduboy.clearDisplay();
	arduboy.display();
}

void loop() {
	arduboy.clearDisplay();
	counter = counter + 1;
	if( counter == 3 ) {
		counter = 0;
		frame = frame + 1;
		if( frame == 3 ) {
			frame = 0;
		}
	}
	if(frame == 1) {
		arduboy.drawBitmap(0, 0, frameone, 16, 16, WHITE);
	}
	if(frame == 2) {
		arduboy.drawBitmap(0, 0, frame two, 16, 16, WHITE);
	}
	if(frame == 3) {
		arduboy.drawBitmap(0, 0, framethree, 16, 16, WHITE);
	}
	arduboy.display();
}

NOTE: I do not have an Arduboy to test this on, so I cannot be sure it’s correct.

This code should work this way: The loop will loop around and clear the display, then counter will increase. When it gets to 3, it’ll reset to 0 and increase frame. If frame is ever 3, then it’ll reset to 0, too. The second part of the loop is simple… If frame is 1, then output the first frame. If it’s 2, then output the second frame. If it’s 3, then output the third frame.

1 Like

It sounds like you want to put your frames into an array and then index into the array with your frame number. There’s no need to convert the frame number to a string unless you want to actually display that number on the screen.

http://www.cplusplus.com/doc/tutorial/arrays/

#include <Arduboy.h>

Arduboy arduboy;

PROGMEM const unsigned char animation[][32] =
{
 {
  0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
  0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
  0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
 },
 {
  0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
  0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
  0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
 },
 {
  0x00, 0x00, 0x00, 0x80, 0x00, 0x78, 0x78, 0x68,
  0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x73, 0x4b, 0x67, 0x14, 0x0c,
  0x14, 0x67, 0x4b, 0x70, 0x40, 0x00, 0x00, 0x00,
 }
};

int animNum = 0;

void setup() {
  arduboy.begin();
  arduboy.setFrameRate(15); // Set to 15 frames per second
}

void loop() {
  if (!arduboy.nextFrame()) { // if not time for the next frame
    return;
  }
  
  arduboy.clear();
  arduboy.drawBitmap(0, 0, animation[animNum], 16, 16, WHITE);
  arduboy.display();

  if (arduboy.everyXFrames(3)) { // if 3 frames have elapsed
    animNum++;
    if (animNum == 3 ) {
      animNum = 0;
    }
  }
}
1 Like

Thank you so much! I was able to get it done! Now I have a different problem; I have a menu, and I want an “in-game,” but with the “loop” function I can’t put it in my original file, so do I put it in a .cpp? If so, what do I put in the matching .h?

By the way, I’m so sorry for asking for so much, I really just want to understand this new language. Please forgive me.

Everyone helping in here deserves a million arduboy points!

1 Like

Hi @Cyndelia,

best thing you can do, is put your code into a Github project, this way, everybody can help with your code :slight_smile:
Once you’ve done that, post the link to the github page.

Ok, I see. I’ll post it in a new topic once its up.

Using multiple files won’t help whatever you’re trying to accomplish. You can put as many functions in the main .ino file as you wish. The only thing having multiple files sometimes helps with is organisation and readability.

Also, you can have multiple .ino files in the same sketch. They will all be joined together during the compile process. Using another .ino file is usually easier that using a .cpp and .h file pair.

1 Like

OK, I created the new topic. Go ahead and take a look:
http://community.arduboy.com/t/github-arduboy-rpg/1876

Great write up in here… Although it’s not that bad, you don’t have to call it shit :smiley:

2 Likes

HAHAHAHA!!! WOW! Thank you!! D:

It’s better to break things out of that cursed .ino file. The more we can do to get away from the ino filetype the better.

Here is a good read that might help reinforce way this the .ino is counterproductive in the long run, http://hackaday.com/2015/07/28/embed-with-elliot-there-is-no-arduino-language/.

1 Like

It’s probably not the best idea to discuss this sort of thing in a topic started by a beginner just starting out in the Arduino world. Things are already going to be confusing enough.

The Arduboy is intended to use the Arduino environment (I think that’s why it’s called Arduboy). We point people to the documentation and tutorials provided by Arduino as a resource for learning how to write “sketches” for the Arduboy. Now you’re suggesting that some of that information is bad and shouldn’t be followed? What’s a beginner going to think of this?

2 Likes

True! Although it’s nice to have access to some sneak peaks in where a topic can go, my comment could easily be confusing and might just kludge up the learning process for new users.

So, @Cyndelia: embrace the .ino file! It is Arduino the way! And there is really nothing wrong with it when using the Arduino platform. And there is zero sarcasm in any of those statements. I was a little dramatic in calling the ino file ending cursed : P.

Check out the article I linked in my previous post to get some more information on how c/c++ is used by the Arduino project behind the scenes.

1 Like