Hello, Iam making an awesome christmas present a custom pcb badge.
Everything works great with hooked up uno, but its heart is actually a Attiny13a, where I get ONLY around
1024bytes (mine code has 1944)
64bytes of variabels (I somehow managed to make few things copy on run so i barely get to it at 59 bytes)
The thing is how can I make this even smaller??
void setup() {
pinMode(3, INPUT_PULLUP);
}
void charlie(int a[])
{
if(a[0] < 0){
pinMode(5, INPUT);
}else
{
pinMode(5, OUTPUT);
digitalWrite(5, a[0]);
}
if(a[1] < 0){
pinMode(6, INPUT);
}else
{
pinMode(6, OUTPUT);
digitalWrite(6, a[1]);
}
if(a[2] < 0){
pinMode(2, INPUT);
}else
{
pinMode(2, OUTPUT);
digitalWrite(2, a[2]);
}
if(a[3] < 0){
pinMode(4, INPUT);
}else
{
pinMode(4, OUTPUT);
digitalWrite(4, a[3]);
}
}
void copy(int* src, int* dst, int len) {
memcpy(dst, src, sizeof(src[0])*len);
}
void resetP()
{
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(2, INPUT);
pinMode(4, INPUT);
}
void loop() {
int koz1[4] = {-2,LOW,HIGH,-2};
//int koz2[4] = {-2,HIGH,LOW,-2};
int koz2[4];
copy(koz1, koz2, 4);
koz2[1] = HIGH;
koz2[2] = LOW;
int koz3[4] = {LOW,HIGH,-2,-2};
//int koz4[4] = {HIGH,LOW,-2,-2};
int koz4[4];
copy(koz3, koz4, 4);
koz4[0] = HIGH;
koz4[1] = LOW;
int koz5[4] = {LOW, -2,-2,HIGH};
//int koz6[4] = {HIGH, -2,-2,LOW};
int koz6[4];
copy(koz5, koz6, 4);
koz4[0] = HIGH;
koz4[3] = LOW;
int cap[4] = {-2, HIGH,-2,LOW};
int oko1[4] = {LOW, -2,HIGH,-2};
//int oko2[4] = {HIGH, -2,LOW,-2};
int oko2[4];
copy(oko1, oko2, 4);
oko2[0] = HIGH;
oko2[2] = LOW;
// put your main code here, to run repeatedly:
static long oldTime = 0;
long Ctime = millis();
long diffT = Ctime - oldTime;
oldTime = Ctime;
static bool holdButt = false;
static long holdTime = 0;
static long shortPressATime = 0;
//static long longPressATime = 0;
static bool kozichOn = true;
//charlie(oko1);
//charlie(oko2);
if(digitalRead(3) == LOW)
{
holdButt = true;
holdTime = holdTime + diffT;
}
else if (holdButt && digitalRead(3) == HIGH){
holdButt = false;
if(holdTime > 1000){
//longPressATime = 5000;
kozichOn = !kozichOn;
}
else
{
shortPressATime = 5000;
}
holdTime = 0;
}
if(shortPressATime > 0)
{
shortPressATime = shortPressATime - diffT;
/*charlie(koz1);
charlie(koz2);
charlie(koz3);
charlie(koz4);
charlie(koz5);
charlie(koz6);
charlie(cap);
*/
if(((round(shortPressATime/100) / 2) & 1) == 0){
charlie(oko1);
charlie(oko2);
resetP();
}
else{
}
}
/*
else if (longPressATime > 0)
{
longPressATime = longPressATime - diffT;
charlie(oko1);
delay(5000/longPressATime);
charlie(oko2);
delay(5000/longPressATime);
longPressATime = longPressATime - 5000/longPressATime;
longPressATime = longPressATime - 5000/longPressATime;
}*/
else{
if(kozichOn){
charlie(koz1);
charlie(koz2);
charlie(koz3);
charlie(koz4);
charlie(koz5);
charlie(koz6);
charlie(cap);
}
charlie(oko1);
charlie(oko2);
}
resetP();
}
EDIT: Attached the file itself in the meantime i saved like 10bytes by making the reset direct
firecat.ino (3.23 KB)