Part 2 of help!
Remember the thing of the string to double thing?
I need help again! I made a few changes to my code
For some reason the screen says:
Type item price
start over?nclDo
19 Replies
This code?
(deleted because long and not helpful)
You'll need to say what's changed (or paste the code again)
@MinecraftFan69420 You'll need to paste the code again to show us what you've changed (I'll delete my paste of it) done
Oh OK
@WeeGee
if you add
ino
to right after the first ``` ticks, then it'll color codeLet's see
like this
```ino
(you put the code here)
```
Oh
Does it work for other languages?
First python
yeah!
py
is python
Second javascript
OOH
That's cool but can you help me first?
@WeeGee ? Hello?
trying to understand what you're saying happens when you run the code; your LCD shows
on the lines?
Yes
and you expect something different, what do you expect to see?
So the first thing the home screen
Shows
(the x represents the ttoal)
Pressing C takes you to the screen where you clear all
It says
Then after a second
it says
Wait BRB
I think that the issue is that you're not overwriting the parts of the screen you expect to:
looks like you're overwriting two lines without a full clear:
note that this is similar to what you see, but with a
written after it
Then after a second it says
@WeeGee So how to fix?
@WeeGee Hello?
I've recreated this in Wokwi here and it does just as you show:
https://wokwi.com/projects/429394747609747457
PriceTotaler - Wokwi ESP32, STM32, Arduino Simulator
Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!
The problem is that you're not waiting for button input, your main
loop
is just running free
You're printing things on top of each other because the main loop isn't ever "waiting" to see if the user presses anything
This if
statement is not running when you don't press any keys, so the code (when no keys are pressed) looks like this:
The next issue is that you don't have any break
statements in your switch-case
so each of your cases is running one after the other, which means the code is effectively doing this:
and that's not really what you want
(each case
is not a separate block; it's just a label that the program "jumps" to depending on what the argument to the switch
statement evaluated to)
so I'd recommend
- making the program wait for input (you can do this by either checking each loop and doing "nothing" if no key is pressed, which would probably look like pulling your switch-case into the if
statement for if(inputkey)
)
- adding break
s to your case
s so that the program doesn't fall-through as is happening now
A sidenote, you're still using double
s to represent dollars and cents; this is a bad idea! things will do weird things if you do this. Don't!
You're also using String
s which is OK, but can be an issue on constrained systems like arduino
@MinecraftFan69420 does this make sense as why your code isn't doing what you expected, and now why your code is doing what it's doing?Gotcha
You'll probably want to read up on
switch-case
@WeeGee Yet another problem
Whenever I press
C
it's supposed to set mode
to 2
, but it's 1
. Why?
Didn't change the code
@WeeGee ello