Hi there,
It's my first post on the forum and I'm pretty new to arduino and coding. I already manage to try different projects and I understand a few basic things about what I want to make.
I'm sorry for the terms I use (english is not my first language). I'd love to manage to do my project by myself (there's so much stuff on this site already) but I can't find to put my hands on a specific tutorial or code.
To put this on simple words my project is this one :
On my Arduino Uno I have an 8x8 led matrix with a MAX7219 (soldered to it) with a push button wired to the arduino. I'm putting the schmatics for you to see.
I want to load my own animated sprites on it and with a button push browse through it (I have 2 animated loops but I want to add more later).
I've been searching for more than a week and I managed to get running codes that print my loops on the matrix but I can't find a way to separate them with the button push...
I tried to take inspiration with codes dealing with "button counter" and "matrix dice" projects but I can't find a way to put the information I need in good use...
I though about using the Parola library because they have a way to put custom characters but I failed to make them work on my code..
With all the codes I tried to mix or create I always ended up with lots of errors and very long lists... I'm sure there are simplier ways but I don't have enough knowledge.
The latest code I stumbled on is a matrix dice I managed to put on my arduino :
#include "LedControl.h"
/*
LedControl lc=LedControl(12,11,10,1);
int button =2;
/* we always wait a bit between updates of the display */
unsigned long delaytime=500;
byte six[8]={B00000000,B11011011,B11011011,B00000000,B00000000,B11011011,B11011011,B00000000};
byte five[8]={B00000000,B01100110,B01100110,B00011000,B00011000,B01100110,B01100110,B00000000};
byte four[8]={B00000000,B01100110,B01100110,B00000000,B00000000,B01100110,B01100110,B00000000};
byte three[8]={B11000000,B11000000,B00000000,B00011000,B00011000,B00000000,B00000011,B00000011};
byte two[8]={B00000000,B00000000,B00000000,B01100110,B01100110,B00000000,B00000000,B00000000};
byte one[8]={B00000000,B00000000,B00000000,B00011000,B00011000,B00000000,B00000000,B00000000};
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
pinMode(button,INPUT);
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,14);
/* and clear the display */
lc.clearDisplay(0);
}
/*
This method will display the characters
(you need at least 7x7 leds to see the whole chars)
*/
void one1() {
/* here is the data for the characters */
/* now display them one by one with a small delay */
lc.setRow(0,0,one[0]);
lc.setRow(0,1,one[1]);
lc.setRow(0,2,one[2]);
lc.setRow(0,3,one[3]);
lc.setRow(0,4,one[4]);
lc.setRow(0,5,one[5]);
lc.setRow(0,6,one[6]);
lc.setRow(0,7,one[7]);
delay(delaytime);
}
void two2() {
/* here is the data for the characters */
/* now display them one by one with a small delay */
lc.setRow(0,0,two[0]);
lc.setRow(0,1,two[1]);
lc.setRow(0,2,two[2]);
lc.setRow(0,3,two[3]);
lc.setRow(0,4,two[4]);
lc.setRow(0,5,two[5]);
lc.setRow(0,6,two[6]);
lc.setRow(0,7,two[7]);
delay(delaytime);
}
void three3() {
/* here is the data for the characters */
/* now display them one by one with a small delay */
lc.setRow(0,0,three[0]);
lc.setRow(0,1,three[1]);
lc.setRow(0,2,three[2]);
lc.setRow(0,3,three[3]);
lc.setRow(0,4,three[4]);
lc.setRow(0,5,three[5]);
lc.setRow(0,6,three[6]);
lc.setRow(0,7,three[7]);
delay(delaytime);
}
void four4() {
/* here is the data for the characters */
/* now display them four by four with a small delay */
lc.setRow(0,0,four[0]);
lc.setRow(0,1,four[1]);
lc.setRow(0,2,four[2]);
lc.setRow(0,3,four[3]);
lc.setRow(0,4,four[4]);
lc.setRow(0,5,four[5]);
lc.setRow(0,6,four[6]);
lc.setRow(0,7,four[7]);
delay(delaytime);
}
void five5() {
/* here is the data for the characters */
/* now display them five by five with a small delay */
lc.setRow(0,0,five[0]);
lc.setRow(0,1,five[1]);
lc.setRow(0,2,five[2]);
lc.setRow(0,3,five[3]);
lc.setRow(0,4,five[4]);
lc.setRow(0,5,five[5]);
lc.setRow(0,6,five[6]);
lc.setRow(0,7,five[7]);
delay(delaytime);
}
void six6() {
/* here is the data for the characters */
/* now display them six by six with a small delay */
lc.setRow(0,0,six[0]);
lc.setRow(0,1,six[1]);
lc.setRow(0,2,six[2]);
lc.setRow(0,3,six[3]);
lc.setRow(0,4,six[4]);
lc.setRow(0,5,six[5]);
lc.setRow(0,6,six[6]);
lc.setRow(0,7,six[7]);
delay(delaytime);
}
void loop() {
int x ;
if(digitalRead(button)== HIGH )
{
x = random(1,7);
switch(x){
case 1 : one1();
break;
case 2 : two2();
break;
case 3 : three3();
break;
case 4 : four4();
break;
case 5 : five5();
break;
case 6 : six6();
break;}
}
}
Obviously I would like to replace the random function by a "croissant?" (1 to ...) one and to replace the sprites/bytes by my own animated ones (i'm putting their codes) :
a kind of circle wheel
const byte IMAGES[][8] = {
{
B00111100,
B01000000,
B10000000,
B10000000,
B10000001,
B10000001,
B01000010,
B00111100
},{
B00111100,
B01000010,
B10000000,
B10000000,
B10000000,
B10000001,
B01000010,
B00111100
},{
B00111100,
B01000010,
B10000001,
B10000000,
B10000000,
B10000000,
B01000010,
B00111100
},{
B00111100,
B01000010,
B10000001,
B10000001,
B10000000,
B10000000,
B01000000,
B00111100
},{
B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000000,
B01000000,
B00111000
},{
B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000000,
B00110000
},{
B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00100000
},{
B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00000100
},{
B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B00000010,
B00001100
},{
B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B00000001,
B00000010,
B00011100
},{
B00111100,
B01000010,
B10000001,
B10000001,
B00000001,
B00000001,
B00000010,
B00111100
},{
B00111100,
B01000010,
B10000001,
B00000001,
B00000001,
B00000001,
B01000010,
B00111100
},{
B00111100,
B01000010,
B00000001,
B00000001,
B00000001,
B10000001,
B01000010,
B00111100
},{
B00111100,
B00000010,
B00000001,
B00000001,
B10000001,
B10000001,
B01000010,
B00111100
},{
B00011100,
B00000010,
B00000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
},{
B00001100,
B00000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
},{
B00000100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
},{
B00100000,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
},{
B00110000,
B01000000,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
},{
B00111000,
B01000000,
B10000000,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
}};
const int IMAGES_LEN = sizeof(IMAGES)/8;
a windmill one :
{B00000000,
B00000000,
B00000000,
B00000000,
B00001000,
B00001100,
B00001110,
B00001100
};{B00000000,
B00000000,
B00000000,
B00000000,
B00001111,
B00000111,
B00000010,
B00000000
};{B00000000,
B00000010,
B00000111,
B00001111,
B00000000,
B00000000,
B00000000,
B00000000
};{ B00001100,
B00001110,
B00001100,
B00001000,
B00000000,
B00000000,
B00000000,
B00000000
};{B00110000,
B01110000,
B00110000,
B00010000,
B00000000,
B00000000,
B00000000,
B00000000
};{B00000000,
B01000000,
B11100000,
B11110000,
B00000000,
B00000000,
B00000000,
B00000000
};{ B00000000,
B00000000,
B00000000,
B00000000,
B11110000,
B11100000,
B01000000,
B00000000
};{B00000000,
B00000000,
B00000000,
B00000000,
B00010000,
B00110000,
B01110000,
B00110000
};
Also , I'm putting the first code that I made with the animations working, there's no button involved in this one but maybe I can incorporate a switch case structure? I don't really know how and where to write it, I tried to look into it but I always end up with a bunch of errors.
#include <LedControl.h>
int DIN = 12;
int CS = 10;
int CLK = 11;
#define button 2
int state = 0;
int old = 0;
int buttonPoll = 0;
//Main
byte A[8] = {B00111100,
B01000000,
B10000000,
B10000000,
B10000000,
B10000000,
B01000010,
B00111100
};
byte B[] = {B00111100,
B01000010,
B10000000,
B10000000,
B10000000,
B10000000,
B01000000,
B00111100
};
byte C[] = { B00111100,
B01000010,
B10000001,
B10000000,
B10000000,
B10000000,
B01000000,
B00111000
};
byte D[] = {B00111100,
B01000010,
B10000001,
B10000001,
B10000000,
B10000000,
B01000000,
B00110000
};
byte E[] = {B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000000,
B01000000,
B00100000
};
byte F[] = {B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000000,
B00000000
};
byte G[] = {B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B10000001,
B00000010,
B00000000
};
byte H[] = {B00111100,
B01000010,
B10000001,
B10000001,
B10000001,
B00000001,
B00000010,
B00000100
};
byte I[] = {B00111100,
B01000010,
B10000001,
B10000001,
B00000001,
B00000001,
B00000010,
B00001100
};
byte J[] = {B00111100,
B01000010,
B10000001,
B00000001,
B00000001,
B00000001,
B00000010,
B00011100
};
byte K[] = {B00111100,
B01000010,
B00000001,
B00000001,
B00000001,
B00000001,
B00000010,
B00111100
};
byte L[] = {B00111100,
B00000010,
B00000001,
B00000001,
B00000001,
B00000001,
B01000010,
B00111100
};
byte M[] = {B00011100,
B00000010,
B00000001,
B00000001,
B00000001,
B10000001,
B01000010,
B00111100
};
byte N[] = {B00001100,
B00000010,
B00000001,
B00000001,
B10000001,
B10000001,
B01000010,
B00111100
};
byte O[] = {B00000100,
B00000010,
B00000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
};
byte P[] = {B00000000,
B00000010,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
};
byte Q[] = {B00000000,
B01000000,
B10000001,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
};
byte R[] = {B00100000,
B01000000,
B10000000,
B10000001,
B10000001,
B10000001,
B01000010,
B00111100
};
byte S[] = {B00110000,
B01000000,
B10000000,
B10000000,
B10000001,
B10000001,
B01000010,
B00111100
};
byte T[] = {B00111000,
B01000000,
B10000000,
B10000000,
B10000000,
B10000001,
B01000010,
B00111100
};
byte Design8[8] = {B00000000,
B00000000,
B00000000,
B00000000,
B00001000,
B00001100,
B00001110,
B00001100
};
byte Design7[8] = {B00000000,
B00000000,
B00000000,
B00000000,
B00001111,
B00000111,
B00000010,
B00000000
};
byte Design6[8] = {B00000000,
B00000010,
B00000111,
B00001111,
B00000000,
B00000000,
B00000000,
B00000000
};
byte Design5[8] = { B00001100,
B00001110,
B00001100,
B00001000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte Design4[8] = {B00110000,
B01110000,
B00110000,
B00010000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte Design3[8] = {B00000000,
B01000000,
B11100000,
B11110000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte Design2[8] = { B00000000,
B00000000,
B00000000,
B00000000,
B11110000,
B11100000,
B01000000,
B00000000
};
byte Design1[8] = {B00000000,
B00000000,
B00000000,
B00000000,
B00010000,
B00110000,
B01110000,
B00110000
};
LedControl lc = LedControl(DIN, CLK, CS, 0);
void setup() {
pinMode(button,INPUT);
lc.shutdown(0, false);
/* Set the brightness to a medium values */
lc.setIntensity(0, 7);
/* and clear the display */
lc.clearDisplay(0);
}
void loop() {
/*windmill pattern */
printByte(Design1);
delay(100);
printByte(Design2);
delay(100);
printByte(Design3);
delay(100);
printByte(Design4);
delay(100);
printByte(Design5);
delay(100);
printByte(Design6);
delay(100);
printByte(Design7);
delay(100);
printByte(Design8);
delay(100);
/*wheel pattern */
printByte(A);
delay(100);
printByte(B);
delay(100);
printByte(C);
delay(100);
printByte(D);
delay(100);
printByte(E);
delay(100);
printByte(F);
delay(100);
printByte(G);
delay(100);
printByte(H);
delay(100);
printByte(I);
delay(100);
printByte(J);
delay(100);
printByte(K);
delay(100);
printByte(L);
delay(100);
printByte(M);
delay(100);
printByte(N);
delay(100);
printByte(O);
delay(100);
printByte(P);
delay(100);
printByte(Q);
delay(100);
printByte(R);
delay(100);
printByte(S);
delay(100);
printByte(T);
}
void printByte(byte character [])
{
int i = 0;
for (i = 0; i < 8; i++)
{
lc.setRow(0, i, character[i]);
}
}
Do you have some leads on where I should dig into? maybe there's a library made for this kind of stuff (the Parola is stuffed with cool effects but for text). If there's a function I should use ? Or maybe you know a project similar to mine.
Thanks for reading and sorry if I made some mistakes (I tried to do this by the rules).