#money-counter

1 messages · Page 1 of 1 (latest)

pure stump
#

can you copy paste the error message you're getting?

#

money-counter

dusty lake
pure stump
#

by the way, some of what you're doing here is probably going to cause premature wear on your EEPROM. But we can address that after we get it compiling 🙂

dusty lake
pure stump
#

I guess I was thinking of the eepromClear function where you write repeatedly to the eeprom. You probably want to make sure those writes are buffered to at least the page size of the eeprom

#

maybe that's done by the eeprom library, idk. I kinda doubt it

dusty lake
#

idk

pure stump
#

but it's not super important for now

dusty lake
#

i was going to work on the eepromClear function later when the code is a bit more complete

pure stump
#

yeah for sure

#

so the immediate problem is that in functions.hpp, you have ledBlink

#

and in the other files you define ledblink

#

so if you capitalize the B, that should fix that

#

or decapitalize the B when you declare it

dusty lake
#

i didn't see that

#

fixed

pure stump
#

nice!

#

You're getting some compiler warnings about readButtons

#

to_add + .01 doesn't change the value of to_add

dusty lake
#

i changed int to float

pure stump
#

Oh yeah I didn't notice that. That's good. But still, you need to assign the value

dusty lake
#

it is? float to_add = 0;

pure stump
#

like if I have:

int main() {
    int a = 0;
    a + 1;
    cout << a << endl
}
``` That's going to print 0
#

I would need to say
a = a + 1

#

or a += 1

#

does that make sense?

dusty lake
#

yes

#

i didn't know about += and -=

pure stump
#

You might be able to simplify that logic a bit too. You're checking if add is true. What if you calculate the amount to either add or subtract, and then at the end either add or subtract depending on whether add is true?

#

instead of calculating the amounts for both negative and positive modes separately

dusty lake
#

good idea

#

idk how tho

#

wait

pure stump
#

yeah so you can do something like

dusty lake
#

this looks much better

#

refresh

#

i am so glad things like github exist

pure stump
#

that looks nice! and now if you change the values you only have to change one place

#

Is the code compiling now?

dusty lake
pure stump
#

ah yeah

#

ok

dusty lake
#

hold on a sec

pure stump
#

I think it's angry because there's a time in both main.o and functions.o?

#

Those warnings about time initialized but declared extern

dusty lake
#

i'm back

pure stump
#

not sure how the compiler/linker is resolving the ambiguity there. Because extern is basically saying "this is in a different file", but then you're also saying "give it this value"

#

so it's probably not respecting you saying it's in a different file

dusty lake
#

ohhhhhh

pure stump
#

how do you feel about putting everything in one file for now

#

and then we can work on breaking stuff out into a different file once we have it compiling in one file?

dusty lake
#

that fixed most of it

dusty lake
#

IT WORKS

#

i just forgot to set money as a value in functions.cpp

#
  • Executing task in folder money-counter: C:.platformio\penv\Scripts\platformio.exe run --environment attiny84

Processing attiny84 (platform: atmelavr; board: attiny84; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny84.html
PLATFORM: Atmel AVR (4.0.0) > Generic ATtiny84
HARDWARE: ATTINY84 8MHz, 512B RAM, 8KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES:

  • framework-arduino-avr-attiny @ 1.5.2
  • toolchain-atmelavr @ 1.70300.191015 (7.3.0)
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 9 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- EEPROM @ 2.0.0
    |-- SoftwareSerial @ 1.0.0
    Building in release mode
    Checking size .pio\build\attiny84\firmware.elf
    Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
    RAM: [=== ] 26.6% (used 136 bytes from 512 bytes)
    Flash: [=== ] 33.9% (used 2776 bytes from 8192 bytes)
    =========================================================================== [SUCCESS] Took 0.85 seconds ===========================================================================
  • Terminal will be reused by tasks, press any key to close it.
#

IT WORKS

pure stump
#

nice!

dusty lake
#

thx for your help i think i got it from here (mostly)

#

i'll post any issues here

#

again thx for all your help

pure stump
#

yeah any time! good luck on the project it looks pretty cool!

dusty lake
#

and i've actually learned (kinda) how to split c++ files and how header files work

pure stump
#

Yeah it can be pretty confusing at first. The rules around global variables aren't always intuitive

#

So like, now you have some globals "living" in your program. They live in the functions.o object file, and since you declared them as extern in the header, main.o knows to look for them outside of itself.

Another way of doing this would be to declare a "blueprint" rather than the actual data, and then build that blueprint in main.cpp

#

I'm not doing a good job of explaining this haha

dusty lake
#

for now it works

pure stump
#

yup 🙂

dusty lake
#

one thing is i haven't tested this on the hardware (still have to solder it together)

pure stump
#

Here's one technique that can help avoid global variables, and the pain that comes with the extern keyword:

#

#include <unistd.h> // for sleep

using namespace std;

struct MyState {
    int time;
    int otherData;
};  

void myFunction(const MyState& state) {
    cout << state.time << endl;
    cout << state.otherData << endl;
}

int main() {
    // setup
    MyState state;   
    state.time = 0; // or millis()?
    state.otherData = 100;
    
    // loop
    while (1) {           
        myFunction(state);            
        sleep(1); // or delay() on arduino?
    }   
}   ```
dusty lake
#

what is that << endl doing?

pure stump
#

that prints a new line

#

that whole cout thing is equivalent to printf("%d\n%d\n", state.time, state.otherData)

#

Passing around state like this has the advantage that you have to be a bit more explicit about what a function has permission to change

#

I'm not really a math guy, but if you recall mathematics, a true function only operates on its inputs right?

#

It can operate on constants too I guess

#

so like, f(x) = y + x wouldn't be a very good function. It should be f(x, y)

dusty lake
#

makes sense

pure stump
#

if there's a magic y sitting around somewhere, how do you know that f(x) does the same thing the next time you call it? Because g(x) might also be doings omething like changing the value of y. And you would never even know, because y isn't even in the function signature for g

#

(or f for that matter

#

So making the reliance on those variables more explicit can be helpful as your program gets bigger

dusty lake
#

so in summary you don't want your functions to affect one another if you don't want it to

pure stump
#

Yeah taht's the general principle

dusty lake
#

HAPPY NEW YEAR

dusty lake
#

In hindsight i should have used a neopixel instead of a standard led

dusty lake
#

1st board done

dusty lake
#

a problem i'm having is i'm using pullups so the digitalRead() always reads yes

#

is there a way to invert the read?

pure stump
#

Wait so when you press the button the result is "false"? That should be fine, can be fixed in software

#

you should be able to replace

if (digitalRead(pin)) {
    // do something
}

with

if (!digitalRead(pin)) {
    // do something
}
#

but if you're using pull-ups and your button also is set up to pull up the input when pressed, then you might have a problem...

#

also are you doing any debouncing?

#

nice looking board btw

dusty lake
#

1: the pins are being pulled to gnd by the buttons 2: i forgot you can just ! a function because i was testing each individually 3: i am doing denouncing in a roundabout way as a side effect of the way i’m stopping multiple inputs from 1 press 4: thx

#

It’s my first time doing a board I designed

dusty lake
#

(in theory) it should be fully working

pure stump
#

nice, congrats!

#

would love to see a video of it in action some day!

dusty lake
#

Maybe