#money-counter
1 messages · Page 1 of 1 (latest)
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 🙂
that's the point of the timeout
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
idk
but it's not super important for now
i was going to work on the eepromClear function later when the code is a bit more complete
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
nice!
You're getting some compiler warnings about readButtons
to_add + .01 doesn't change the value of to_add
i changed int to float
Oh yeah I didn't notice that. That's good. But still, you need to assign the value
it is? float to_add = 0;
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?
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
yeah so you can do something like
that looks nice! and now if you change the values you only have to change one place
Is the code compiling now?
it's still giving this error
hold on a sec
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
i'm back
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
ohhhhhh
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?
probably a good idea
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
nice!
thx for your help i think i got it from here (mostly)
i'll post any issues here
again thx for all your help
yeah any time! good luck on the project it looks pretty cool!
and i've actually learned (kinda) how to split c++ files and how header files work
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
for now it works
yup 🙂
one thing is i haven't tested this on the hardware (still have to solder it together)
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?
  } Â
}Â Â ```
what is that << endl doing?
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)
makes sense
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
so in summary you don't want your functions to affect one another if you don't want it to
Yeah taht's the general principle
HAPPY NEW YEAR
In hindsight i should have used a neopixel instead of a standard led
1st board done
a problem i'm having is i'm using pullups so the digitalRead() always reads yes
is there a way to invert the read?
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
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
(in theory) it should be fully working
Maybe